static unsigned int byte_order()
{
unsigned long test = BYTEORDER_TEST;
- unsigned char* ptr;
- unsigned int order;
- ptr = (unsigned char*)(&test);
- order = (ptr[0] << 12) | (ptr[1] << 8) | (ptr[2] << 4) | ptr[3];
+ unsigned char* ptr = (unsigned char*)(&test);
+ unsigned int order = (ptr[0] << 12) | (ptr[1] << 8) | (ptr[2] << 4) | ptr[3];
return order;
}
static void str2lab(char* dest, const char* src, int len, const char* fmt,
int n)
{
- int j;
-
- j = 0;
+ int j = 0;
if (src != nullptr) {
for (int i=0; i<len && src[i] != '\0'; i++) {
if (isprint(src[i])) {
static void pack_time(time_t t, int32_t* date, int32_t* time)
{
- struct tm* tm;
-
- tm = gmtime(&t);
+ struct tm* tm = gmtime(&t);
*date = tm->tm_mday | ((tm->tm_mon+1)<<8) | ((tm->tm_year+1900)<<16);
*time = t % 86400;
}
static time_t unpack_time(int32_t date, int32_t time)
{
- time_t result;
- short year, month, day;
static int m_to_d[12] =
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
- year = (date >> 16) & 0xffff;
- month = (date >> 8) & 0xff; /* 1-12 */
- day = date & 0xff; /* 1-31 */
+ short year = (date >> 16) & 0xffff;
+ short month = (date >> 8) & 0xff; /* 1-12 */
+ short day = date & 0xff; /* 1-31 */
month -= 1; /* fit struct tm */
year += month / 12;
year -= 1;
month += 12;
}
- result = (year - 1970) * 365 + m_to_d[month];
+ time_t result = (year - 1970) * 365 + m_to_d[month];
if (month <= 1) {
year -= 1;
}
static Waypoint* get_wpt(struct wprdata* wprdata, unsigned n)
{
- struct wpthdr* wpthdr;
- struct wpt* wpt;
- int j, idx;
- Waypoint* WP;
+ int j;
- wpthdr = &(wprdata->wpthdr);
- idx = wpthdr->idx[n];
+ struct wpthdr* wpthdr = &(wprdata->wpthdr);
+ int idx = wpthdr->idx[n];
if (idx == WPT_IDX_NONE || wpthdr->used[idx] == WPT_UNUSED) {
return nullptr;
}
- wpt = &(wprdata->wpt[idx]);
+ struct wpt* wpt = &(wprdata->wpt[idx]);
- WP = new Waypoint;
+ Waypoint* WP = new Waypoint;
WP->latitude = -pt2deg(wpt->pt.y);
WP->longitude = pt2deg(wpt->pt.x);
WP->SetCreationTime(unpack_time(wpt->date, wpt->time));
static void wpr_read()
{
struct wprdata wprdata;
- struct rtehdr* rtehdr;
- struct rte* rte;
- int i, j, idx;
+ int i, j;
Waypoint* WP;
- route_head* RT;
if (gbfread(&wprdata, sizeof(struct wprdata), 1, fin) != 1) {
fatal(MYNAME ": Read error on '%s'. Perhaps this isn't an alan file\n", fin->name);
}
/* routes */
- rtehdr = &(wprdata.rtehdr);
+ struct rtehdr* rtehdr = &(wprdata.rtehdr);
for (i=0; i<MAXRTE; i++) {
- idx = rtehdr->idx[i];
+ int idx = rtehdr->idx[i];
if (idx == RTE_IDX_NONE || rtehdr->used[idx] == RTE_UNUSED) {
continue;
}
- rte = &(wprdata.rte[idx]);
+ struct rte* rte = &(wprdata.rte[idx]);
- RT = route_head_alloc();
+ route_head* RT = route_head_alloc();
RT->rte_num = i;
for (j=RTE_NAME_LEN-1; j >= 0 && rte->name[j] == ' '; j--) {};
char *s = xstrndup(rte->name,j+1);
static void trl_read()
{
struct trldata trldata;
- struct trkhdr* trkhdr;
- struct trklog* trklog;
- Waypoint* WP;
- route_head* TL;
int i, j;
for (i=0; i<MAXTRK; i+=2) {
for (i=0; i<MAXTRK; i++) {
/* track header */
- trkhdr = &(trldata.loghdr.trkhdr[i]);
+ struct trkhdr* trkhdr = &(trldata.loghdr.trkhdr[i]);
if (trkhdr->occupied == TRK_UNUSED) {
continue;
}
- TL = route_head_alloc();
+ route_head* TL = route_head_alloc();
for (j=TRK_NAME_LEN-1;
j >= 0 && (trkhdr->name[j] == ' ' || trkhdr->name[j] == '\0');
j--) {};
track_add_head(TL);
/* track points */
- trklog = &(trldata.trklog[i]);
+ struct trklog* trklog = &(trldata.trklog[i]);
for (j=0; j<trkhdr->totalpt; j++) {
- WP = new Waypoint;
+ Waypoint* WP = new Waypoint;
WP->latitude = -pt2deg(trklog->pt[j].y);
WP->longitude = pt2deg(trklog->pt[j].x);
WP->altitude = hgt2m(trklog->sh[j].height);
static int find_wpt(struct wprdata* wprdata, const Waypoint* WP)
{
- struct wpt pattern, *wpt;
- int wpt_idx;
+ struct wpt pattern;
str2lab(pattern.name, WP->shortname, WPT_NAME_LEN, nullptr, 0);
pattern.pt.x = deg2pt(WP->longitude);
pattern.pt.y = deg2pt(-WP->latitude);
- wpt = wprdata->wpt;
+ struct wpt* wpt = wprdata->wpt;
for (int i = 0; i<MAXWPT; i++) {
- wpt_idx = wprdata->wpthdr.idx[i];
+ int wpt_idx = wprdata->wpthdr.idx[i];
if (wpt_idx == WPT_IDX_NONE ||
wprdata->wpthdr.used[wpt_idx] == WPT_UNUSED) {
continue;
static int add_wpt(struct wprdata* wprdata, const Waypoint* WP,int isroute)
{
- struct wpthdr* wpthdr;
- int hdr_idx, wpt_idx;
struct wpt* wpt;
int i;
- wpthdr = &(wprdata->wpthdr);
+ struct wpthdr* wpthdr = &(wprdata->wpthdr);
- hdr_idx = find_wpt(wprdata, WP);
+ int hdr_idx = find_wpt(wprdata, WP);
if (hdr_idx >= 0) {
/* duplicate waypoint */
if (isroute) {
for (i=0; i<MAXWPT && wpthdr->idx[i] != WPT_IDX_NONE; i++) { }
hdr_idx = i;
for (i=0; i<MAXWPT && wpthdr->used[i] != WPT_UNUSED; i++) { }
- wpt_idx = i;
+ int wpt_idx = i;
if (wpthdr->num >= MAXWPT || hdr_idx >= MAXWPT || wpt_idx >= MAXWPT) {
fatal(MYNAME ": Can't store more than %u waypoints\n", MAXWPT);
}
static void wpr_route_hdr(const route_head* RT)
{
- struct rtehdr* rtehdr;
- int hdr_idx, rte_idx;
- struct rte* rte;
int i;
- rtehdr = &(WPR.rtehdr);
+ struct rtehdr* rtehdr = &(WPR.rtehdr);
for (i=0; i<MAXRTE && rtehdr->idx[i] != RTE_IDX_NONE; i++) { }
- hdr_idx = i;
+ int hdr_idx = i;
for (i=0; i<MAXRTE && rtehdr->used[i] != RTE_UNUSED; i++) { }
- rte_idx = i;
+ int rte_idx = i;
if (rtehdr->num >= MAXRTE || hdr_idx >= MAXRTE || rte_idx >= MAXRTE) {
fatal(MYNAME ": Can't store more than %u routes", MAXRTE);
}
- rte = &(WPR.rte[rte_idx]);
+ struct rte* rte = &(WPR.rte[rte_idx]);
str2lab(rte->name, RT->rte_name, RTE_NAME_LEN, "R%03d", rte_idx);
str2lab(rte->comment, RT->rte_desc, RTE_COMMENT_LEN, nullptr, 0);
pack_time(time(nullptr), &(rte->date), &(rte->time));
static void wpr_route_wpt(const Waypoint* WP)
{
- struct rte* rte;
- int wpt_idx;
-
- rte = &(WPR.rte[WPR.rtehdr.num -1]);
+ struct rte* rte = &(WPR.rte[WPR.rtehdr.num -1]);
if (rte->wptnum >= MAXWPTINRTE) {
fatal(MYNAME ": Can't store more than %u waypoints per route", MAXWPTINRTE);
}
- wpt_idx = add_wpt(&WPR, WP, 1);
+ int wpt_idx = add_wpt(&WPR, WP, 1);
rte->wptidx[rte->wptnum] = wpt_idx;
rte->wptnum ++;
static void trl_track_hdr(const route_head* TL)
{
- struct trkhdr* trkhdr;
- int idx, l;
+ int idx;
- trkhdr = TRL.loghdr.trkhdr;
+ struct trkhdr* trkhdr = TRL.loghdr.trkhdr;
for (idx=0; idx< MAXTRK && trkhdr[idx].occupied != TRK_UNUSED; idx++) {};
if (idx >= MAXTRK) {
if (TL->rte_desc != nullptr) {
strncpy(trkhdr[idx].comment, CSTRc(TL->rte_desc), TRK_COMMENT_LEN);
- l = strlen(CSTRc(TL->rte_desc));
+ int l = strlen(CSTRc(TL->rte_desc));
if (l < TRK_COMMENT_LEN-1) {
memset(trkhdr[idx].comment + l, ' ', TRK_COMMENT_LEN - l);
}
static void trl_track_wpt(const Waypoint* WP)
{
- struct trklog* trklog;
- struct trkhdr* trkhdr;
- int trk_idx, log_idx;
+ int trk_idx = TRL.loghdr.num;
- trk_idx = TRL.loghdr.num;
-
- trkhdr = &(TRL.loghdr.trkhdr[trk_idx]);
+ struct trkhdr* trkhdr = &(TRL.loghdr.trkhdr[trk_idx]);
if (trkhdr->totalpt >= MAXPTINTRK) {
fatal(MYNAME ": Can't store more than %u points per track", MAXPTINTRK);
}
- log_idx = trkhdr->next;
+ int log_idx = trkhdr->next;
- trklog = &(TRL.trklog[trk_idx]);
+ struct trklog* trklog = &(TRL.trklog[trk_idx]);
trklog->pt[log_idx].x = deg2pt(WP->longitude);
trklog->pt[log_idx].y = deg2pt(-WP->latitude);
if WAYPT_HAS(WP, speed) {
static void trl_track_tlr(const route_head*)
{
- struct trkhdr* trkhdr;
- int trk_idx;
-
- trk_idx = TRL.loghdr.num;
- trkhdr = &(TRL.loghdr.trkhdr[trk_idx]);
+ int trk_idx = TRL.loghdr.num;
+ struct trkhdr* trkhdr = &(TRL.loghdr.trkhdr[trk_idx]);
if (trkhdr->totalpt == 0) {
trkhdr->occupied = TRK_UNUSED;
static void trl_write()
{
- struct trkhdr* trkhdr;
- void* buf;
int i;
- size_t fill;
TRL.loghdr.id = TRL_HDR_ID;
TRL.loghdr.num = TRL.loghdr.next = -1;
TRL.loghdr.date = TRL.loghdr.time = 0;
for (i=0; i<MAXTRK; i++) {
- trkhdr = &(TRL.loghdr.trkhdr[i]);
+ struct trkhdr* trkhdr = &(TRL.loghdr.trkhdr[i]);
trkhdr->totalpt = 0;
trkhdr->next = 0;
memset(trkhdr->name, 0, TRK_NAME_LEN);
trl_swap(&TRL);
- fill = 0x10000 - 2 * sizeof(struct trklog);
- buf = xmalloc(fill);
+ size_t fill = 0x10000 - 2 * sizeof(struct trklog);
+ void* buf = xmalloc(fill);
if (buf == nullptr) {
fatal(MYNAME ": Not enough memory\n");
}
static void Read_AN1_Waypoint(gbfile* f, an1_waypoint_record* wpt)
{
- unsigned short len;
-
wpt->magic = ReadShort(f);
wpt->unk1 = ReadLong(f);
wpt->lon = ReadLong(f);
wpt->visible_zoom = ReadChar(f);
wpt->unk5 = ReadShort(f);
wpt->radius = ReadDouble(f);
- len = ReadShort(f);
+ unsigned short len = ReadShort(f);
wpt->name = ReadString(f, len);
if (len != strlen(wpt->name)) {
ofs += 2;
if (len) {
- char* oldurlstr;
/*
* Trust URL encoded in new format over one in
* old format if both are present. Whack the
* name starting at '{URL='.
*/
- oldurlstr = strstr(wpt->name, "{URL=");
+ char* oldurlstr = strstr(wpt->name, "{URL=");
if (oldurlstr) {
*oldurlstr = 0;
}
static void Read_AN1_Line(gbfile* f, an1_line_record* line)
{
-
- short len;
-
line->roadtype = ReadLong(f);
line->serial = ReadShort(f);
line->unk2 = ReadLong(f);
line->unk3 = ReadShort(f);
line->type = ReadShort(f);
line->unk4 = ReadLong(f);
- len = ReadShort(f);
+ short len = ReadShort(f);
line->name = ReadString(f, len);
line->lineweight = ReadShort(f);
line->linestyle = ReadLong(f);
static void Write_AN1_Line(gbfile* f, an1_line_record* line)
{
- short len;
-
WriteLong(f, line->roadtype);
WriteShort(f, line->serial);
WriteLong(f, line->unk2);
WriteShort(f, line->unk3);
WriteShort(f, line->type);
WriteLong(f, line->unk4);
- len = strlen(line->name);
+ short len = strlen(line->name);
WriteShort(f, len);
WriteString(f, line->name);
WriteShort(f, (short) line->lineweight);
static void Skip_AN1_BM(gbfile* f)
{
- unsigned long bmsize;
- unsigned long palettesize;
- unsigned long bmisize;
- unsigned long bitoffset;
-
Skip(f, 8); /* BITMAPFILEHEADER fields 1-3 */
- bitoffset = ReadLong(f);
+ unsigned long bitoffset = ReadLong(f);
- bmisize = ReadLong(f);
+ unsigned long bmisize = ReadLong(f);
Skip(f, 16); /* BITMAPINFOHEADER fields 2-6 */
- bmsize = ReadLong(f);
+ unsigned long bmsize = ReadLong(f);
Skip(f, 16); /* BITMAPINFOHEADER fields 8-11 */
- palettesize = bitoffset - bmisize - 14;
+ unsigned long palettesize = bitoffset - bmisize - 14;
Skip(f, bmsize + palettesize);
}
static void Read_AN1_Symbol(gbfile* f, an1_symbol_record* symbol)
{
- short len;
-
/* This is just the high word of a long; we ate the low
* word in the caller. Fortunately, we don't care. */
symbol->hotspotxhi = ReadShort(f);
symbol->hotspoty = ReadLong(f);
symbol->unk1 = ReadLong(f);
ReadGuid(f, &symbol->guid);
- len = ReadChar(f);
+ short len = ReadChar(f);
symbol->name = ReadString(f, len);
}
static void Read_AN1_Header(gbfile* f)
{
- unsigned short magic;
- unsigned short type;
-
- magic = ReadShort(f);
+ unsigned short magic = ReadShort(f);
(void) magic; // hush warning.
- type = ReadShort(f);
+ unsigned short type = ReadShort(f);
last_read_type = type;
}
static void Read_AN1_Bitmaps(gbfile* f)
{
- long count;
an1_symbol_record symbol;
- count = ReadLong(f);
+ long count = ReadLong(f);
while (count) {
unsigned short magic = ReadShort(f);
static void Read_AN1_Waypoints(gbfile* f)
{
- Waypoint* wpt_tmp;
char* icon = nullptr;
ReadShort(f);
unsigned long count = ReadLong(f);
for (unsigned long i = 0; i < count; i++) {
an1_waypoint_record* rec = Alloc_AN1_Waypoint();
Read_AN1_Waypoint(f, rec);
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
if (rec->creation_time) {
wpt_tmp->SetCreationTime(rec->creation_time);
static void Read_AN1_Lines(gbfile* f)
{
- route_head* rte_head;
- Waypoint* wpt_tmp;
-
ReadShort(f);
unsigned long count = ReadLong(f);
for (unsigned long i = 0; i < count; i++) {
an1_line_record* rec = Alloc_AN1_Line();
Read_AN1_Line(f, rec);
/* create route rec */
- rte_head = route_head_alloc();
+ route_head* rte_head = route_head_alloc();
rte_head->line_color.bbggrr = rec->linecolor;
if (rec->opacity == 0x8200) {
rte_head->line_color.opacity = 128;
Read_AN1_Vertex(f, vert);
/* create route point */
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
wpt_tmp->latitude = DecodeOrd(vert->lat);
wpt_tmp->longitude = -DecodeOrd(vert->lon);
wpt_tmp->shortname = QString().sprintf("\\%5.5lx", rtserial++);
RteHdFunctor<ArcDistanceFilter> arcdist_arc_disp_hdr_cb_f(this, &ArcDistanceFilter::arcdist_arc_disp_hdr_cb);
queue* elem, * tmp;
- unsigned removed;
if (arcfileopt) {
int fileline = 0;
char* line;
- gbfile* file_in;
- Waypoint* arcpt2, * arcpt1;
- file_in = gbfopen(arcfileopt, "r", MYNAME);
+ gbfile* file_in = gbfopen(arcfileopt, "r", MYNAME);
- arcpt1 = new Waypoint;
- arcpt2 = new Waypoint;
+ Waypoint* arcpt1 = new Waypoint;
+ Waypoint* arcpt2 = new Waypoint;
arcdist_arc_disp_hdr_cb(nullptr);
arcpt2->latitude = arcpt2->longitude = BADVAL;
track_disp_all(arcdist_arc_disp_hdr_cb_f, nullptr, arcdist_arc_disp_wpt_cb_f);
}
- removed = 0;
+ unsigned removed = 0;
#if NEWQ
foreach (Waypoint* wp, waypt_list) {
#else
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
Waypoint* wp = (Waypoint*) elem;
#endif
- extra_data* ed;
- ed = (extra_data*) wp->extra_data;
+ extra_data* ed = (extra_data*) wp->extra_data;
wp->extra_data = nullptr;
if (ed) {
if ((ed->distance >= pos_dist) == (exclopt == nullptr)) {
static void
bcr_handle_icon_str(const char* str, Waypoint* wpt)
{
- bcr_icon_mapping_t* m;
-
wpt->icon_descr = BCR_DEF_MPS_ICON;
- for (m = bcr_icon_mapping; (m->bcr_name); m++) {
+ for (bcr_icon_mapping_t* m = bcr_icon_mapping; (m->bcr_name); m++) {
if (case_ignore_strcmp(str, m->bcr_name) == 0) {
- int nr;
-
if (m->symbol_DE == nullptr) {
if (! m->warned) {
m->warned = true;
}
wpt->description = m->symbol_DE;
if (m->mps_name != nullptr) {
- nr = gt_find_icon_number_from_desc(m->mps_name, MAPSOURCE);
+ int nr = gt_find_icon_number_from_desc(m->mps_name, MAPSOURCE);
wpt->icon_descr = gt_find_desc_from_icon_number(nr, MAPSOURCE);
}
return;
const char* result = BCR_DEF_ICON;
if (!icon_descr.isNull()) {
- bcr_icon_mapping_t* m;
-
- for (m = bcr_icon_mapping; (m->bcr_name); m++) {
+ for (bcr_icon_mapping_t* m = bcr_icon_mapping; (m->bcr_name); m++) {
if (! m->mps_name) {
continue;
}
static void
bcr_create_waypts_from_route(route_head* route)
{
- Waypoint* wpt;
queue* elem, *tmp;
QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
- wpt = new Waypoint(*(Waypoint*) elem);
+ Waypoint* wpt = new Waypoint(*(Waypoint*) elem);
waypt_add(wpt);
}
}
static void
bcr_wgs84_to_mercator(const double lat, const double lon, int* north, int* east)
{
- double N, E;
-
- N = log(tan(lat * M_PI / 360 + M_PI / 4)) * radius;
- E = lon * radius * M_PI / 180.0;
+ double N = log(tan(lat * M_PI / 360 + M_PI / 4)) * radius;
+ double E = lon * radius * M_PI / 180.0;
if (lat > 0) {
N += 0.500000000001; /* we go from double to integer */
static void
bcr_data_read()
{
- int index;
char* str;
- route_head* route;
- route = route_head_alloc();
+ route_head* route = route_head_alloc();
if ((str = inifile_readstr(ini, "client", "routename"))) {
route->rte_name = str;
route_add_head(route);
- for (index = 1; index > 0; index ++) {
+ for (int index = 1; index > 0; index ++) {
char station[32];
char* str;
int mlat, mlon; /* mercator data */
- Waypoint* wpt;
snprintf(station, sizeof(station), "STATION%d", index);
if (nullptr == (str = inifile_readstr(ini, "coordinates", station))) {
fatal(MYNAME ": structure error at %s (Coordinates)!\n", station);
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->shortname = station;
bcr_mercator_to_wgs84(mlat, mlon, &wpt->latitude, &wpt->longitude);
if (nullptr != (str = inifile_readstr(ini, "client", station))) {
- char* cx;
-
- cx = strchr(str, ',');
+ char* cx = strchr(str, ',');
if (cx == nullptr) {
fatal(MYNAME ": structure error at %s (Client)!\n", station);
}
}
if (nullptr != (str = inifile_readstr(ini, "description", station))) {
- char* c;
-
- c = strchr(str, ',');
+ char* c = strchr(str, ',');
if (c != nullptr) {
*c = '\0';
}
/* so we respectfully add a CR/LF on each line */
gbfprintf(fout, "%s\r\n", CSTR(key));
} else {
- char* tmp;
-
- tmp = (value != nullptr) ? xstrdup(value) : xstrdup("");
+ char* tmp = (value != nullptr) ? xstrdup(value) : xstrdup("");
if (index != nullptr) {
gbfprintf(fout, "%s%d=%s\r\n", CSTR(key), *index, tmp);
} else {
{
queue* elem, *tmp;
Waypoint* wpt;
- QString sout;
- int i, north, east, nmin, nmax, emin, emax;
+ int north, east, nmax, emin;
curr_rte_num++;
if (curr_rte_num != target_rte_num) {
bcr_write_line(fout, "[CLIENT]", nullptr, nullptr); /* client section */
bcr_write_line(fout, "REQUEST", nullptr, "TRUE");
- sout = route->rte_name;
+ QString sout = route->rte_name;
if (rtename_opt != nullptr) {
sout = rtename_opt;
}
bcr_write_line(fout, "DESCRIPTIONLINES", nullptr, "0");
- i = 0;
+ int i = 0;
QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
- const char* icon;
Waypoint* wpt = (Waypoint*) elem;
i++;
- icon = get_bcr_icon_from_icon_descr(wpt->icon_descr);
+ const char* icon = get_bcr_icon_from_icon_descr(wpt->icon_descr);
sout = QString("%1,%2").arg(icon).arg(BCR_UNKNOWN,10);
bcr_write_line(fout, "STATION", &i, sout);
bcr_write_line(fout, "[COORDINATES]", nullptr, nullptr); /* coords section */
- nmin = emin = (1<<30);
- emax = nmax = -nmin;
+ int nmin = emin = (1<<30);
+ int emax = nmax = -nmin;
i = 0;
QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
i = 0;
QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
- QString s1, s2;
+ QString s2;
i++;
wpt = (Waypoint*) elem;
- s1 = wpt->notes;
+ QString s1 = wpt->notes;
if (s1.isEmpty()) {
s1 = wpt->description;
}
{
double distance = gcdist(lat_orig, long_orig,
lat_orig_adj, long_orig_adj);
- double frac;
double lat_dest;
double long_dest;
distance = radtometers(distance);
return nullptr;
}
- frac = maxDist / distance;
+ double frac = maxDist / distance;
linepart(lat_orig, long_orig, lat_orig_adj, long_orig_adj, frac,
&lat_dest, &long_dest);
static void data_read()
{
unsigned char ibuf[25];
- int rd_cnt;
if (global_opts.debug_level >= 0) {
puts(MYNAME ": Select recorded flight in memo mode.");
state = st_sync;
for (;;) {
/* wait up to 5 seconds for more data */
- rd_cnt = gbser_read_wait(serial_handle, ibuf, reqd_bytes[state], 5000);
+ int rd_cnt = gbser_read_wait(serial_handle, ibuf, reqd_bytes[state], 5000);
if (rd_cnt < 0) {
fatal(MYNAME ": Serial error\n");
} else if (rd_cnt < reqd_bytes[state]) {
static unsigned int
bushnell_get_icon_from_name(QString name)
{
- icon_mapping_t* t;
-
if (name.isNull()) {
name = "Waypoint";
}
- for (t = bushnell_icons; t->icon != nullptr; t++) {
+ for (icon_mapping_t* t = bushnell_icons; t->icon != nullptr; t++) {
if (0 == name.compare(t->icon, Qt::CaseInsensitive)) {
return t->symbol;
}
static const char*
bushnell_get_name_from_symbol(signed int s)
{
- icon_mapping_t* t;
- for (t = bushnell_icons; t->icon != nullptr; t++) {
+ for (icon_mapping_t* t = bushnell_icons; t->icon != nullptr; t++) {
if (s == t->symbol) {
return t->icon;
}
static void
bushnell_read()
{
- int32_t lat_tmp,lon_tmp;
- unsigned int proximity;
- unsigned int icon;
Waypoint* wpt_tmp = new Waypoint;
- lat_tmp = gbfgetint32(file_in);
- lon_tmp = gbfgetint32(file_in);
+ int32_t lat_tmp = gbfgetint32(file_in);
+ int32_t lon_tmp = gbfgetint32(file_in);
- icon = gbfgetc(file_in);
+ unsigned int icon = gbfgetc(file_in);
wpt_tmp->icon_descr = bushnell_get_name_from_symbol(icon);
- proximity = gbfgetc(file_in); // 1 = off, 3 = proximity alarm.
+ unsigned int proximity = gbfgetc(file_in); // 1 = off, 3 = proximity alarm.
(void) proximity;
wpt_tmp->latitude = lat_tmp / 10000000.0;
wpt_tmp->longitude = lon_tmp / 10000000.0;
{
char tbuf[20]; // 19 text bytes + null terminator.
char padding[2] = {0, 0};
- gbfile* file_out;
static int wpt_count;
QString fname(ofname);
fname += "-";
fname += QString::number(wpt_count++);
fname += ".wpt";
- file_out = gbfopen_le(fname, "wb", MYNAME);
+ gbfile* file_out = gbfopen_le(fname, "wb", MYNAME);
gbfputint32(round(wpt->latitude * 10000000), file_out);
gbfputint32(round(wpt->longitude * 10000000), file_out);
gbfputc(bushnell_get_icon_from_name(wpt->icon_descr), file_out);
static void
bushnell_read()
{
- int lat_tmp,lon_tmp;
-
while (true) {
- Waypoint* wpt_tmp;
-
- lat_tmp = gbfgetint32(file_in);
- lon_tmp = gbfgetint32(file_in);
+ int lat_tmp = gbfgetint32(file_in);
+ int lon_tmp = gbfgetint32(file_in);
if (!lat_tmp && !lon_tmp) {
break;
}
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
wpt_tmp->latitude = lat_tmp / 10000000.0;
wpt_tmp->longitude = lon_tmp / 10000000.0;
int
cet_char_to_ucs4(const char src, const cet_cs_vec_t* vec, int* value)
{
- int trash, c;
- int* dest;
+ int trash;
- c = ((unsigned char)src & 0xFF);
- dest = (value != nullptr) ? value : &trash;
+ int c = ((unsigned char)src & 0xFF);
+ int* dest = (value != nullptr) ? value : &trash;
*dest = c;
c -= vec->ucs4_offset;
{
int result;
unsigned char trash[16];
- unsigned char* c;
- c = (dest != nullptr) ? (unsigned char*) dest : trash;
+ unsigned char* c = (dest != nullptr) ? (unsigned char*) dest : trash;
if ((value & 0xffffff80) == 0) { /* <= 7 bits */
if (dest_size < 1) {
{
if (str) {
const char* cin = str;
- char* res, *cout;
+ char* cout;
int len = 0;
- res = cout = xstrdup(cin);
+ char* res = cout = xstrdup(cin);
while (*cin && (len < maxlen)) {
int bytes, value;
cet_str_utf8_to_any(const char* src, const cet_cs_vec_t* vec)
{
const char* c = src;
- int len;
- char* res, *dest;
- const char* cend;
+ char* dest;
if (c == nullptr) {
return nullptr;
return xstrdup(src); /* UTF-8 -> UTF-8 */
}
- len = strlen(c);
- res = dest = (char*) xmalloc(len + 1); /* target will become smaller or equal length */
+ int len = strlen(c);
+ char* res = dest = (char*) xmalloc(len + 1); /* target will become smaller or equal length */
- cend = c + len;
+ const char* cend = c + len;
while (c < cend) {
int bytes;
char*
cet_str_any_to_utf8(const char* src, const cet_cs_vec_t* vec)
{
- int len, value;
- char* result, *cout;
- const char* cin;
+ int value;
+ char* cout;
char temp = CET_NOT_CONVERTABLE_DEFAULT;
- cin = src;
+ const char* cin = src;
if (cin == nullptr) {
return nullptr;
}
return xstrdup(src); /* UTF-8 -> UTF-8 */
}
- len = 0;
+ int len = 0;
while (*cin != '\0') { /* determine length of resulting UTF-8 string */
if (CET_ERROR == cet_char_to_ucs4(*cin++, vec, &value)) {
cet_char_to_ucs4(temp, vec, &value);
len += cet_ucs4_to_utf8(nullptr, 6, value);
}
- result = cout = (char*) xmalloc(len + 1);
+ char* result = cout = (char*) xmalloc(len + 1);
cin = src;
while (*cin != '\0') {
char*
cet_str_uni_to_utf8(const short* src, const int length)
{
- int i, len;
- unsigned short* cin;
- char* res, *cout;
+ char* cout;
if (src == nullptr) {
return nullptr;
}
- len = 0;
- i = length;
- cin = (unsigned short*)src;
+ int len = 0;
+ int i = length;
+ unsigned short* cin = (unsigned short*)src;
while (i-- > 0) {
len += cet_ucs4_to_utf8(nullptr, 6, le_read16(cin++));
}
- res = cout = (char*) xmalloc(len + 1);
+ char* res = cout = (char*) xmalloc(len + 1);
cin = (unsigned short*)src;
i = length;
cet_str_any_to_uni(const char* src, const cet_cs_vec_t* vec, int* length)
{
char* utf8;
- int len;
- short* res, *sout;
+ short* sout;
if (! src) {
utf8 = xstrdup("");
utf8 = cet_str_any_to_utf8(src, vec);
}
- len = cet_utf8_strlen(utf8);
- res = sout = (short int*) xcalloc(2, len + 1);
+ int len = cet_utf8_strlen(utf8);
+ short* res = sout = (short int*) xcalloc(2, len + 1);
if (len) {
char* cin = utf8;
char*
cet_str_any_to_any(const char* src, const cet_cs_vec_t* src_vec, const cet_cs_vec_t* dest_vec)
{
- char* c0, *c1;
const cet_cs_vec_t* v_in = (src_vec != nullptr) ? src_vec : &cet_cs_vec_ansi_x3_4_1968;
const cet_cs_vec_t* v_out = (dest_vec != nullptr) ? dest_vec : &cet_cs_vec_ansi_x3_4_1968;
return xstrdup(src);
}
- c0 = (v_in == &cet_cs_vec_utf8) ? xstrdup(src) : cet_str_any_to_utf8(src, v_in);
- c1 = (v_out == &cet_cs_vec_utf8) ? xstrdup(c0) : cet_str_utf8_to_any(c0, v_out);
+ char* c0 = (v_in == &cet_cs_vec_utf8) ? xstrdup(src) : cet_str_any_to_utf8(src, v_in);
+ char* c1 = (v_out == &cet_cs_vec_utf8) ? xstrdup(c0) : cet_str_utf8_to_any(c0, v_out);
xfree(c0);
return c1;
if (cet_cs_vec_ct > 0) {
cet_cs_vec_t* p;
- cet_cs_alias_t* list;
c = 0;
/* enumerate count of all names and aliases */
}
/* create name to vec table */
- list = (cet_cs_alias_t*) xcalloc(c, sizeof(*list));
+ cet_cs_alias_t* list = (cet_cs_alias_t*) xcalloc(c, sizeof(*list));
i = 0;
for (p = cet_cs_vec_root; p != nullptr; p = p->next) {
if (p->alias != nullptr) {
cet_cs_vec_t*
cet_find_cs_by_name(const QString& name)
{
- int i, j;
-
cet_register();
if (cet_cs_alias == nullptr) {
return nullptr;
}
- i = 0;
- j = cet_cs_alias_ct - 1;
+ int i = 0;
+ int j = cet_cs_alias_ct - 1;
while (i <= j) {
- int a, x;
- cet_cs_alias_t* n;
-
- a = (i + j) >> 1;
- n = &cet_cs_alias[a];
- x = case_ignore_strcmp(name, n->name);
+ int a = (i + j) >> 1;
+ cet_cs_alias_t* n = &cet_cs_alias[a];
+ int x = case_ignore_strcmp(name, n->name);
if (x == 0) {
return n->vec;
} else if (x < 0) {
int
cet_validate_cs(const QString& cs, cet_cs_vec_t** vec, QString* cs_name)
{
- cet_cs_vec_t* v;
-
if (cs.isEmpty()) { /* set default us-ascii */
*vec = &cet_cs_vec_ansi_x3_4_1968;
*cs_name = CET_CHARSET_ASCII;
return 1;
}
- v = cet_find_cs_by_name(cs);
+ cet_cs_vec_t* v = cet_find_cs_by_name(cs);
if (v != nullptr) {
// TODO: make v->name into q QString and replace this...
char* tmp = xstrdup(v->name);
char*
cet_convert_string(char* str)
{
- char* res;
-
if (str == nullptr) {
return nullptr; /* return origin if empty or NULL */
} else if (*str == '\0') {
return str;
}
- res = converter(str);
+ char* res = converter(str);
xfree(str);
return res;
}
cet_convert_waypt(const Waypoint* wpt)
{
Waypoint* w = const_cast<Waypoint*>(wpt);
- format_specific_data* fs;
if ((cet_output == 0) && (w->wpt_flags.cet_converted != 0)) {
return;
w->wpt_flags.cet_converted = 1;
- fs = wpt->fs;
+ format_specific_data* fs = wpt->fs;
while (fs != nullptr) {
if (fs->convert != nullptr) {
fs->convert(fs);
compegps_parse_date(const char* c, struct tm* tm)
{
char month[4];
- int year;
tm->tm_mday = atoi(c);
strncpy(month, c+3, 3);
month[3] = 0;
tm->tm_mon = month_lookup(month);
- year = atoi(c + 7);
+ int year = atoi(c + 7);
if (year < 70) {
year += 100;
}
parse_wpt(char* buff)
{
int col = -1;
- char* c, *cx;
+ char* cx;
Waypoint* wpt = new Waypoint;
struct tm tm;
int has_time = 0;
memset(&tm, 0, sizeof(tm));
- c = strstr(buff, "A ");
+ char* c = strstr(buff, "A ");
if (c == buff) {
col++;
}
static void
parse_wpt_info(const char* buff, Waypoint* wpt) /* "w" */
{
- char* c;
int col = -1;
double fx;
- c = csv_lineparse(buff, ",", "", col++);
+ char* c = csv_lineparse(buff, ",", "", col++);
while (c != nullptr) {
c = lrtrim(c);
if (*c != '\0') {
parse_trkpt(char* buff)
{
int col = -1;
- char* c;
struct tm tm;
Waypoint* wpt = new Waypoint;
- c = strstr(buff, "A ");
+ char* c = strstr(buff, "A ");
if (c == buff) {
col++;
}
static void
parse_track_info(const char* buff, route_head* track) /* "t" */
{
- char* c;
int col = -1;
- c = csv_lineparse(buff, "|", "", col++);
+ char* c = csv_lineparse(buff, "|", "", col++);
while (c != nullptr) {
c = lrtrim(c);
if (*c != '\0') {
static void
parse_rte_info(const char* buff, route_head* route) /* "R" */
{
- char* c;
int col = -1;
- c = csv_lineparse(buff, ",", "", col++);
+ char* c = csv_lineparse(buff, ",", "", col++);
while (c != nullptr) {
c = lrtrim(c);
if (*c != '\0') {
route_head* track = nullptr;
while ((buff = gbfgetstr(fin))) {
- char* ctail;
-
if ((line++ == 0) && fin->unicode) {
cet_convert_init(CET_CHARSET_UTF8, 1);
}
continue;
}
- ctail = strchr(cin, ' ');
+ char* ctail = strchr(cin, ' ');
if (ctail == nullptr) {
continue;
}
static void
write_waypt_cb(const Waypoint* wpt)
{
- QString name;
-
if (curr_index != target_index) {
return;
}
QString cleaned_name(wpt->shortname);
cleaned_name.replace(' ', '_');
- name = (snlen > 0) ? mkshort(sh, cleaned_name) : cleaned_name;
+ QString name = (snlen > 0) ? mkshort(sh, cleaned_name) : cleaned_name;
gbfprintf(fout, "W %s A ", CSTR(name));
gbfprintf(fout, "%.10f%c%c ",
cst_make_url(char* str)
{
int len = strlen(str);
- char* res;
if (len < 3) {
return nullptr;
if (strstr(str, "://") > str) {
return xstrdup(str);
} else if (strstr(str, ":\\") == str+1) { /* DOS 0.01++ file format */
- res = xstrdup("file://*:");
+ char* res = xstrdup("file://*:");
res[7] = *str++;
res[8] = *str++;
res = xstrappend(res, str);
{
- char* c;
- int i;
-
- c = res; /* replace all backslashes with a slash */
+ char* c = res; /* replace all backslashes with a slash */
while ((c = strchr(c, '\\'))) {
*c++ = '/';
}
c = res; /* enumerate number of spaces within filename */
- i = 0;
+ int i = 0;
while ((c = strchr(c, ' '))) {
c++;
i++;
}
if (i > 0) { /* .. and replace them with "%20" */
- char* src, *dest, *last;
+ char* src, *dest;
- last = src = res;
+ char* last = src = res;
res = dest = (char*) xcalloc(strlen(src) + (2*i) + 1, 1);
while ((c = strchr(src, ' '))) {
if (c != src) {
csv_lineparse(const char* stringstart, const char* delimited_by,
const char* enclosed_in, const int line_no)
{
- const char* sp;
static const char* p = nullptr;
static char* tmp = nullptr;
size_t dlen = 0, elen = 0, efound = 0;
int enclosedepth = 0;
- short int dfound;
short int hyper_whitespace_delimiter = 0;
if (tmp) {
}
/* the beginning of the string we start with (this pass) */
- sp = p;
+ const char* sp = p;
/* length of delimiters and enclosures */
if ((delimited_by) && (!hyper_whitespace_delimiter)) {
if (enclosed_in) {
elen = strlen(enclosed_in);
}
- dfound = 0;
+ short int dfound = 0;
while ((*p) && (!dfound)) {
if ((elen) && (strncmp(p, enclosed_in, elen) == 0)) {
decdir_to_dec(const char* decdir)
{
char* p;
- const char* cp;
- double rval;
int sign = 0;
- cp = &decdir[0];
+ const char* cp = &decdir[0];
if ((*cp == 'W') || (*cp == 'S')) {
sign = -1;
sign = 1;
}
- rval = sign ? strtod(&decdir[1], &p) : strtod(&decdir[0], &p);
+ double rval = sign ? strtod(&decdir[1], &p) : strtod(&decdir[0], &p);
if (sign == 0) {
if ((*p == 'W') || (*p == 'S')) {
int hour =0;
int min =0;
int sec =0;
- int ac;
char* ampm = (char*) xmalloc(strlen(s) + 1);
- ac = sscanf(s, format, &hour, &min, &sec, ampm);
+ int ac = sscanf(s, format, &hour, &min, &sec, ampm);
/* If no time format in arg string, assume AM */
if (ac < 4) {
ampm[0] = 0;
break;
/* ALTITUDE CONVERSIONS ************************************************/
case XT_ALT_FEET: {
- /* altitude in feet as a decimal value */
- double val;
char *endptr;
- val = strtod(s, &endptr);
+ double val = strtod(s, &endptr);
if ((val == 0 && s==endptr)) {
wpt->altitude = unknown_alt;
} else {
}
break;
case XT_ALT_METERS: {
- /* altitude in meters as a decimal value */
- double val;
char *endptr;
- val = strtod(s, &endptr);
+ double val = strtod(s, &endptr);
if ((val == 0 && s==endptr)) {
wpt->altitude = unknown_alt;
} else {
xcsv_data_read(void)
{
char* buff = nullptr;
- char* s;
- Waypoint* wpt_tmp;
int linecount = 0;
- queue* elem;
- field_map_t* fmp;
route_head* rte = nullptr;
route_head* trk = nullptr;
utm_northing = 0;
}
}
if (strlen(buff)) {
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
- s = buff;
+ char* s = buff;
s = csv_lineparse(s, CSTR(xcsv_file.field_delimiter),
CSTR(xcsv_file.field_encloser), linecount);
}
/* reset the ifield queue */
- elem = QUEUE_FIRST(&xcsv_file.ifield);
+ queue* elem = QUEUE_FIRST(&xcsv_file.ifield);
/* now rip the line apart, advancing the queue for each tear
* off the beginning of buff since there's no index into queue.
*/
while (s) {
- fmp = (field_map_t*) elem;
+ field_map_t* fmp = (field_map_t*) elem;
xcsv_parse_val(s, wpt_tmp, fmp, &trk);
elem = QUEUE_NEXT(elem);
xcsv_waypt_pr(const Waypoint* wpt)
{
QString buff;
- int i;
- field_map_t* fmp;
queue* elem, *tmp;
double latitude, longitude;
int32 utmz;
&latitude, &longitude, &alt, xcsv_file.gps_datum);
}
- i = 0;
+ int i = 0;
QUEUE_FOR_EACH(xcsv_file.ofield, elem, tmp) {
double lat = latitude;
double lon = longitude;
*/
int field_is_unknown = 0;
- fmp = (field_map_t*) elem;
+ field_map_t* fmp = (field_map_t*) elem;
if ((i != 0) && !(fmp->options & OPTIONS_NODELIM)) {
*xcsv_file.stream << write_delimiter;
foreach (Waypoint* waypointp, waypt_list) {
#else
queue* elem, *tmp;
- Waypoint* waypointp;
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
- waypointp = (Waypoint*) elem;
+ Waypoint* waypointp = (Waypoint*) elem;
#endif
if ((se == nullptr) || (waypointp->session == se)) {
if (global_opts.verbose_status) {
static void
gpl_read()
{
- Waypoint* wpt_tmp;
- route_head* track_head;
gpl_point_t gp;
- double alt_feet;
- track_head = route_head_alloc();
+ route_head* track_head = route_head_alloc();
track_add_head(track_head);
while (gbfread(&gp, sizeof(gp), 1, gplfile_in) > 0) {
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
wpt_tmp->latitude = le_read_double(&gp.lat);
wpt_tmp->longitude = le_read_double(&gp.lon);
- alt_feet = le_read_double(&gp.alt);
+ double alt_feet = le_read_double(&gp.alt);
wpt_tmp->altitude = FEET_TO_METERS(alt_feet);
if (wpt_tmp->altitude <= unknown_alt + 1) {
wpt_tmp->altitude = unknown_alt;
write_wcstr(const QString& str)
{
int len;
- short* unicode;
- unicode = cet_str_utf8_to_uni(CSTR(str), &len);
+ short* unicode = cet_str_utf8_to_uni(CSTR(str), &len);
gbfwrite((void*)unicode, 2, len + 1, fout);
xfree(unicode);
}
static int
read_until_wcstr(const char* str)
{
- char* buff;
- int len, sz;
int eos = 0, res = 0;
- len = strlen(str);
- sz = (len + 1) * 2;
- buff = (char*) xcalloc(sz, 1);
+ int len = strlen(str);
+ int sz = (len + 1) * 2;
+ char* buff = (char*) xcalloc(sz, 1);
while (! gbfeof(fin)) {
static void
destinator_read_poi()
{
- Waypoint* wpt;
int count = 0;
gbfrewind(fin);
while (!(gbfeof(fin))) {
- QString str, hnum;
- double ll;
+ QString str;
garmin_fs_t* gmsd;
if (count == 0) {
count++;
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->shortname = read_wcstr(0);
wpt->notes = read_wcstr(0); /* comment */
- hnum = read_wcstr(0); /* house number */
+ QString hnum = read_wcstr(0); /* house number */
str = read_wcstr(0); /* street */
if (str.isEmpty()) {
wpt->longitude = gbfgetdbl(fin);
wpt->latitude = gbfgetdbl(fin);
- ll = gbfgetdbl(fin);
+ double ll = gbfgetdbl(fin);
if (ll != wpt->longitude) {
fatal(MYNAME "_poi: Invalid file!\n");
}
gbfrewind(fin);
while (!(gbfeof(fin))) {
- QString str;
- Waypoint* wpt;
-
if (count == 0) {
- str = read_wcstr(0);
+ QString str = read_wcstr(0);
if ((str != DST_ITINERARY)) {
fatal(MYNAME "_itn: Invalid record header!\n");
}
count++;
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->shortname = read_wcstr(0);
wpt->notes = read_wcstr(0);
gbfrewind(fin);
while (!(gbfeof(fin))) {
- Waypoint* wpt;
struct tm tm;
char buff[20];
- int date;
recno++;
break;
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->longitude = gbfgetdbl(fin);
wpt->latitude = gbfgetdbl(fin);
gbfseek(fin, 12 * sizeof(int32_t), SEEK_CUR); /* SAT info */
- date = gbfgetint32(fin);
+ int date = gbfgetint32(fin);
double milliseconds = gbfgetflt(fin);
gbfseek(fin, 2 * 12, SEEK_CUR); /* SAT info */
static void
destinator_read()
{
- int i0, i1;
double d0, d1;
char buff[16];
fatal(MYNAME ": Unexpected EOF (end of file)!\n");
}
- i0 = le_read32(&buff[0]);
- i1 = le_read32(&buff[4]);
+ int i0 = le_read32(&buff[0]);
+ int i1 = le_read32(&buff[4]);
if ((i0 == 0x690043) && (i1 == 0x790074)) {
if (data_type != rtedata) {
}
if (wpt->creation_time.isValid()) {
- struct tm tm;
- double milliseconds;
- int date;
const time_t ct = wpt->GetCreationTime().toTime_t();
- tm = *gmtime(&ct);
+ struct tm tm = *gmtime(&ct);
tm.tm_mon += 1;
tm.tm_year -= 100;
- date = (tm.tm_mday * 10000) + (tm.tm_mon * 100) + tm.tm_year;
+ int date = (tm.tm_mday * 10000) + (tm.tm_mon * 100) + tm.tm_year;
gbfputint32(date, fout);
- milliseconds = (tm.tm_hour * 10000) +
- (tm.tm_min * 100) + tm.tm_sec;
+ double milliseconds = (tm.tm_hour * 10000) +
+ (tm.tm_min * 100) + tm.tm_sec;
milliseconds = (milliseconds * 1000) + (wpt->GetCreationTime().time().msec());
gbfputflt(milliseconds, fout);
dg100_send(uint8_t cmd, const void* payload, size_t param_len)
{
uint8_t frame[FRAME_MAXLEN];
- uint16_t checksum, payload_len;
- size_t framelen;
- int n;
- payload_len = 1 + param_len;
+ uint16_t payload_len = 1 + param_len;
/* Frame length calculation:
* frame start sequence(2), payload length field(2), command id(1),
* param(variable length),
* checksum(2), frame end sequence(2) */
- framelen = 2 + 2 + 1 + param_len + 2 + 2;
+ size_t framelen = 2 + 2 + 1 + param_len + 2 + 2;
assert(framelen <= FRAME_MAXLEN);
/* create frame head + command */
memcpy(frame + 5, payload, param_len);
/* create frame tail */
- checksum = dg100_checksum(frame + 4, framelen - 8);
+ uint16_t checksum = dg100_checksum(frame + 4, framelen - 8);
be_write16(frame + framelen - 4, checksum);
be_write16(frame + framelen - 2, 0xB0B3);
- n = gbser_write(serial_handle, frame, framelen);
+ int n = gbser_write(serial_handle, frame, framelen);
if (global_opts.debug_level) {
struct dg100_command* cmdp = dg100_findcmd(cmd);
static int
dg100_recv_byte()
{
- int result;
-
/* allow for a delay of 40s;
* erasing the whole DG-100 memory takes about 21s */
- result = gbser_readc_wait(serial_handle, 40000);
+ int result = gbser_readc_wait(serial_handle, 40000);
switch (result) {
case gbser_ERROR:
fatal("dg100_recv_byte(): error reading one byte\n");
dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload)
{
static uint8_t buf[FRAME_MAXLEN];
- uint16_t frame_start_seq, payload_len_field;
- uint16_t payload_end_seq, payload_checksum, frame_end_seq;
- uint16_t frame_head, numheaders, sum;
- uint8_t c, cmd;
- int i, param_len, frame_len;
- struct dg100_command* cmdinfo;
+ uint16_t payload_end_seq;
+ uint8_t c;
/* consume input until frame head sequence 0xA0A2 was received */
- frame_head = 0;
+ uint16_t frame_head = 0;
dg100_debug("Receiving ", 0, 0, nullptr);
do {
c = dg100_recv_byte();
*/
/* read Payload Length, Command ID, and two further bytes */
- i = gbser_read_wait(serial_handle, &buf[2], 5, 1000);
+ int i = gbser_read_wait(serial_handle, &buf[2], 5, 1000);
if (i < 5) {
fatal("Expected to read 5 bytes, but got %d\n", i);
}
dg100_debug("", 0, 5, &buf[2]);
- payload_len_field = be_read16(buf + 2);
- cmd = buf[4];
+ uint16_t payload_len_field = be_read16(buf + 2);
+ uint8_t cmd = buf[4];
/*
* getconfig/setconfig have the same answer ID -
cmd = dg100cmd_setconfig;
}
- cmdinfo = dg100_findcmd(cmd);
+ struct dg100_command* cmdinfo = dg100_findcmd(cmd);
if (!cmdinfo) {
/* TODO: consume data until frame end signature,
* then report failure to the caller? */
fatal("unknown answer ID %02x\n", cmd);
}
- param_len = cmdinfo->recvsize;
+ int param_len = cmdinfo->recvsize;
/*
* the getfileheader answer has a varying param_len,
* we need to calculate it
*/
if (cmd == dg100cmd_getfileheader) {
- numheaders = be_read16(buf + 5);
+ uint16_t numheaders = be_read16(buf + 5);
param_len = 2 + 2 + 12 * numheaders;
}
* frame start sequence(2), payload length field(2), command id(1),
* param(variable length),
* payload end sequence(2 or 0), checksum(2), frame end sequence(2) */
- frame_len = 2 + 2 + 1 + param_len + ((model->has_payload_end_seq) ? 2 : 0) + 2 + 2;
+ int frame_len = 2 + 2 + 1 + param_len + ((model->has_payload_end_seq) ? 2 : 0) + 2 + 2;
if (frame_len > FRAME_MAXLEN) {
fatal("frame too large (frame_len=%d, FRAME_MAXLEN=%d)\n",
}
dg100_debug("", 0, frame_len - 7, &buf[7]);
- frame_start_seq = be_read16(buf + 0);
+ uint16_t frame_start_seq = be_read16(buf + 0);
payload_len_field = be_read16(buf + 2);
if (model->has_payload_end_seq) {
payload_end_seq = be_read16(buf + frame_len - 6);
}
- payload_checksum = be_read16(buf + frame_len - 4);
- frame_end_seq = be_read16(buf + frame_len - 2);
+ uint16_t payload_checksum = be_read16(buf + frame_len - 4);
+ uint16_t frame_end_seq = be_read16(buf + frame_len - 2);
(void) payload_end_seq;
(void) frame_end_seq;
frame_start_seq, payload_len_field, cmdinfo->text);
/* calculate checksum */
- sum = dg100_checksum(buf + 4, frame_len - 8);
+ uint16_t sum = dg100_checksum(buf + 4, frame_len - 8);
if (sum != payload_checksum) {
fatal("checksum mismatch: data sum is 0x%04x, checksum received is 0x%04x\n",
sum, payload_checksum);
static int
dg100_recv(uint8_t expected_id, void* buf, unsigned int len)
{
- int n;
struct dg100_command* cmdinfo;
uint8_t* data;
- unsigned int copysize, trailing_bytes;
- n = dg100_recv_frame(&cmdinfo, &data);
+ int n = dg100_recv_frame(&cmdinfo, &data);
/* check whether the received frame matches the expected answer type */
if (cmdinfo->id != expected_id) {
return -1;
}
- trailing_bytes = (model->has_trailing_bytes) ? (cmdinfo->trailing_bytes) : 0;
- copysize = n - trailing_bytes;
+ unsigned int trailing_bytes = (model->has_trailing_bytes) ? (cmdinfo->trailing_bytes) : 0;
+ unsigned int copysize = n - trailing_bytes;
/* check for buffer overflow */
if (len < copysize) {
static int
dg100_request(uint8_t cmd, const void* sendbuf, void* recvbuf, size_t count)
{
- struct dg100_command* cmdinfo;
-
- cmdinfo = dg100_findcmd(cmd);
+ struct dg100_command* cmdinfo = dg100_findcmd(cmd);
assert(cmdinfo != nullptr);
dg100_send(cmd, sendbuf, cmdinfo->sendsize);
static char*
read_str(gbfile* f)
{
- int i;
- char* res;
-
- i = gbfgetc(f);
+ int i = gbfgetc(f);
if (i == 0xff) {
i = gbfgetint16(f);
}
- res = (char*) xmalloc(i + 1);
+ char* res = (char*) xmalloc(i + 1);
res[i] = '\0';
if (i) {
gbfread(res, 1, i, f);
static int
read_datum(gbfile* f)
{
- int res;
- char* d, *g;
-
- d = read_str(f);
- g = read_str(f);
+ char* d = read_str(f);
+ char* g = read_str(f);
- res = GPS_Lookup_Datum_Index(d);
+ int res = GPS_Lookup_Datum_Index(d);
if (*g && (strcmp(d, g) != 0)) {
fatal(MYNAME ": Unsupported combination of datum '%s' and grid '%s'!\n",
read_CTrackFile(const int version)
{
char buf[128];
- int32_t ver;
- int32_t tcount, wcount;
- int16_t u1;
- int32_t ux;
- route_head* track;
int i;
- u1 = gbfgetint16(fin);
+ int16_t u1 = gbfgetint16(fin);
gbfread(buf, 1, 10, fin);
if ((u1 != 0x0a) || (strncmp("CTrackFile", buf, 10) != 0)) {
gbfseek(fin, 36, SEEK_CUR); /* skip unknown 36 bytes */
}
- ver = gbfgetint32(fin);
+ int32_t ver = gbfgetint32(fin);
if (ver != version) {
fatal(MYNAME ": Unknown or invalid track file (%d).\n", ver);
}
- ux = gbfgetint32(fin); // Unknown 2
+ int32_t ux = gbfgetint32(fin); // Unknown 2
ux = gbfgetint32(fin); // Unknown 3
ux = gbfgetint32(fin); // Unknown 4
(void) ux; // Silence warning.
- track = route_head_alloc();
+ route_head* track = route_head_alloc();
track_add_head(track);
/* S1 .. S9: comments, hints, jokes, aso */
xfree(s);
}
- tcount = gbfgetint32(fin);
+ int32_t tcount = gbfgetint32(fin);
int datum = 118;
if (tcount > 0) {
datum = read_datum(fin);
if (version == 8) {
- int len;
-
gbfread(buf, 1, 4, fin);
- len = gbfgetint16(fin);
+ int len = gbfgetint16(fin);
gbfseek(fin, len, SEEK_CUR);
}
}
while (tcount > 0) {
- Waypoint* wpt;
-
tcount--;
if (version == 8) {
datum = read_datum(fin);
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = gbfgetdbl(fin);
wpt->longitude = gbfgetdbl(fin);
}
while (! gbfeof(fin)) {
- Waypoint* wpt;
-
i = gbfgetc(fin);
if (i == 0) {
break;
gbfungetc(i, fin);
datum = read_datum(fin);
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = gbfgetdbl(fin);
wpt->longitude = gbfgetdbl(fin);
return;
}
- wcount = gbfgetint32(fin);
+ int32_t wcount = gbfgetint32(fin);
if (wcount == 0) {
return;
}
datum = read_datum(fin);
while (wcount > 0) {
- Waypoint* wpt;
- int32_t namect;
-
wcount--;
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = gbfgetdbl(fin);
wpt->longitude = gbfgetdbl(fin);
convert_datum(wpt, datum);
- namect = gbfgetint32(fin);
+ int32_t namect = gbfgetint32(fin);
// variants of shortname
for (int32_t i = 0; i < namect; i++) {
- char* name;
-
- name = read_str(fin);
+ char* name = read_str(fin);
if (name && *name) {
switch (i) {
case 0:
char out[DEFLATE_BUFF_SIZE];
char* cout = nullptr;
uint32_t bytes = 0;
- uint32_t have;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
(void)inflateEnd(&strm);
return res;
}
- have = DEFLATE_BUFF_SIZE - strm.avail_out;
+ uint32_t have = DEFLATE_BUFF_SIZE - strm.avail_out;
if (have > 0) {
cout = (char*) xrealloc(cout, bytes + have);
memcpy(cout+bytes, out, have);
static void
write_header(const route_head* trk)
{
- int count;
const char ZERO = '\0';
header_written = 1;
- count = 0;
+ int count = 0;
if (trk != nullptr) {
queue* curr, *prev;
QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++;
static void
wpt_cb(const Waypoint* wpt)
{
- int names;
-
gbfputdbl(wpt->latitude, fout);
gbfputdbl(wpt->longitude, fout);
gbfputdbl(wpt->altitude != unknown_alt ? wpt->altitude : 0, fout);
- names = 1;
+ int names = 1;
if (!wpt->description.isEmpty()) {
names = 2;
}
DuplicateFilter::btree_node* DuplicateFilter::addnode(btree_node* tree, btree_node* newnode, btree_node** oldnode)
{
- btree_node* tmp, * last = nullptr;
+ btree_node* last = nullptr;
if (*oldnode) {
*oldnode = nullptr;
return (newnode);
}
- tmp = tree;
+ btree_node* tmp = tree;
while (tmp) {
last = tmp;
} dupe;
Waypoint* delwpt = nullptr;
- int i, ct = waypt_count();
- wpt_ptr* htable, *bh;
+ int ct = waypt_count();
queue* elem, *tmp;
- htable = (wpt_ptr*) xmalloc(ct * sizeof(*htable));
- bh = htable;
+ wpt_ptr* htable = (wpt_ptr*) xmalloc(ct * sizeof(*htable));
+ wpt_ptr* bh = htable;
- i = 0;
+ int i = 0;
#if NEWQ
foreach (Waypoint* waypointp, waypt_list) {
bh->wpt = waypointp;
static void
rd_init(const QString& fname)
{
- int sz;
char ibuf[100] = {'0'} ;
const char* ezsig = "TerraByte Location File";
file_in = gbfopen_le(fname, "rb", MYNAME);
- sz = gbfread(ibuf, 1, 52, file_in);
+ int sz = gbfread(ibuf, 1, 52, file_in);
if ((sz < 52) ||
strncmp(ibuf, ezsig, strlen(ezsig)) ||
char p;
char ibuf[10];
do {
- unsigned char tag;
- Waypoint* wpt_tmp;
-
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
UrlLink link;
- for (tag = gbfgetc(file_in); tag != 0xff; tag = gbfgetc(file_in)) {
+ for (unsigned char tag = gbfgetc(file_in); tag != 0xff; tag = gbfgetc(file_in)) {
switch (tag) {
case 1:
wpt_tmp->shortname = gbfgetpstr(file_in);
qint64 mSecsSinceEpoc = gpsbabeltime.toMSecsSinceEpoch();
gpsbabeltime.setMSecsSinceEpoch(mSecsSinceEpoc-mSecsSinceEpoc%1000);
- Waypoint* waypt;
- waypt = new Waypoint;
+ Waypoint* waypt = new Waypoint;
waypt->latitude = (point.Latitude / 1000000.0);
waypt->longitude = (point.Longitude / 1000000.0);
waypt->altitude = point.Altitude;
/* copy file to memory stream (needed for seek-ops and piped commands) */
file_in = gbfopen(nullptr, "wb", MYNAME);
- gbsize_t size;
- size = gbfcopyfrom(file_in, fileorg_in, 0x7FFFFFFF);
+ gbsize_t size = gbfcopyfrom(file_in, fileorg_in, 0x7FFFFFFF);
if(global_opts.debug_level > 1) {
printf (MYNAME " filesize=%d\n",size);
}
static QString
exif_time_str(const time_t time)
{
- struct tm tm;
-
- tm = *localtime(&time);
+ struct tm tm = *localtime(&time);
tm.tm_year += 1900;
tm.tm_mon += 1;
static double
exif_read_double(const exif_tag_t* tag, const int index)
{
- unsigned int num, den;
int32_t* data = (int32_t*)tag->data;
- num = data[index * 2];
- den = data[(index * 2) + 1];
+ unsigned int num = data[index * 2];
+ unsigned int den = data[(index * 2) + 1];
if (den == 0) {
den = 1;
}
static double
exif_read_coord(const exif_tag_t* tag)
{
- double res, min, sec;
-
- res = exif_read_double(tag, 0);
+ double res = exif_read_double(tag, 0);
if (tag->count == 1) {
return res;
}
- min = exif_read_double(tag, 1);
+ double min = exif_read_double(tag, 1);
res += (min / 60);
if (tag->count == 2) {
return res;
}
- sec = exif_read_double(tag, 2);
+ double sec = exif_read_double(tag, 2);
res += (sec / 3600);
return res;
static time_t
exif_read_timestamp(const exif_tag_t* tag)
{
- double hour, min, sec;
-
- hour = exif_read_double(tag, 0);
- min = exif_read_double(tag, 1);
- sec = exif_read_double(tag, 2);
+ double hour = exif_read_double(tag, 0);
+ double min = exif_read_double(tag, 1);
+ double sec = exif_read_double(tag, 2);
return ((int)hour * SECONDS_PER_HOUR) + ((int)min * 60) + (int)sec;
}
exif_read_datestamp(const exif_tag_t* tag)
{
struct tm tm;
- char* str;
memset(&tm, 0, sizeof(tm));
- str = xstrndup((char*)tag->data, tag->size);
+ char* str = xstrndup((char*)tag->data, tag->size);
sscanf(str, "%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
xfree(str);
uint32_t* exif_ifd_ofs, uint32_t* gps_ifd_ofs, uint32_t* inter_ifd_ofs)
{
queue* elem, *tmp;
- exif_ifd_t* ifd;
gbfile* fin = app->fexif;
- ifd = (exif_ifd_t*) xcalloc(sizeof(*ifd), 1);
+ exif_ifd_t* ifd = (exif_ifd_t*) xcalloc(sizeof(*ifd), 1);
QUEUE_INIT(&ifd->tags);
ENQUEUE_TAIL(&app->ifds, &ifd->Q);
ifd->nr = ifd_nr;
}
for (uint16_t i = 0; i < ifd->count; i++) {
- exif_tag_t* tag;
-
- tag = (exif_tag_t*) xcalloc(sizeof(*tag), 1);
+ exif_tag_t* tag = (exif_tag_t*) xcalloc(sizeof(*tag), 1);
#ifdef EXIF_DBG
offs = gbftell(fin);
tag->offs = offs;
QUEUE_FOR_EACH(&ifd->tags, elem, tmp) {
exif_tag_t* tag = (exif_tag_t*)elem;
if ((tag->size > 4) && (tag->value)) {
- char* ptr;
-
tag->data = xmalloc(tag->size);
tag->data_is_dynamic = 1;
- ptr = (char*) tag->data;
+ char* ptr = (char*) tag->data;
gbfseek(fin, tag->value, SEEK_SET);
if (BYTE_TYPE(tag->type)) {
static void
exif_examine_app(exif_app_t* app)
{
- uint16_t endianess;
- uint32_t ident;
gbfile* ftmp = exif_app->fcache;
gbfrewind(ftmp);
- ident = gbfgetuint32(ftmp);
+ uint32_t ident = gbfgetuint32(ftmp);
is_fatal(ident != 0x66697845, MYNAME ": Invalid EXIF header magic.");
is_fatal(gbfgetint16(ftmp) != 0, MYNAME ": Error in EXIF header.");
- endianess = gbfgetint16(ftmp);
+ uint16_t endianess = gbfgetint16(ftmp);
#ifdef EXIF_DBG
printf(MYNAME ": endianess = 0x%04X\n", endianess);
{
QDateTime res;
- exif_tag_t* tag;
-
- tag = exif_find_tag(app, EXIF_IFD, 0x9003); /* DateTimeOriginal from EXIF */
+ exif_tag_t* tag = exif_find_tag(app, EXIF_IFD, 0x9003); /* DateTimeOriginal from EXIF */
if (! tag) {
tag = exif_find_tag(app, IFD0, 0x0132); /* DateTime from IFD0 */
}
}
if (tag) {
- char* str;
-
- str = exif_read_str(tag);
+ char* str = exif_read_str(tag);
res = QDateTime::fromString(str, "yyyy:MM:dd hh:mm:ss");
xfree(str);
}
static Waypoint*
exif_waypt_from_exif_app(exif_app_t* app)
{
- Waypoint* wpt;
queue* elem, *tmp;
- exif_ifd_t* ifd;
exif_tag_t* tag;
char lat_ref = '\0';
char lon_ref = '\0';
time_t timestamp = UNKNOWN_TIMESTAMP;
time_t datestamp = UNKNOWN_TIMESTAMP;
- ifd = exif_find_ifd(app, GPS_IFD);
+ exif_ifd_t* ifd = exif_find_ifd(app, GPS_IFD);
if (ifd == nullptr) {
return nullptr;
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = unknown_alt;
wpt->longitude = unknown_alt;
}
if (opt_filename) {
- char* c, *cx;
+ char* c;
char* str = xstrdup(fin->name);
- cx = str;
+ char* cx = str;
if ((c = strrchr(cx, ':'))) {
cx = c + 1;
}
char sval[16], snum[16];
char dot = 0;
int den1 = 1;
- int num1, num2, den2, rem;
- char* cx;
- double vx;
if (val < 0.000000001) {
val = 0.0;
fatal(MYNAME ": Value (%f) to big for a rational representation!\n", val);
}
- num1 = 0;
- vx = fabs(val);
+ int num1 = 0;
+ double vx = fabs(val);
while (vx > 1) {
num1++;
vx = vx / 10;
snprintf(sval, sizeof(sval), "%*.*f", 9, 9 - num1, fabs(val));
snum[0] = '\0';
- cx = sval;
+ char* cx = sval;
while (*cx) {
if (dot) {
den1 *= 10;
*den = den1;
}
- num2 = num1;
- den2 = den1;
- rem = 1;
+ int num2 = num1;
+ int den2 = den1;
+ int rem = 1;
/* Euclid's Algorithm to find the gcd */
while (num2 % den2) {
exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16_t type, const uint32_t count, const int index, const void* data)
{
exif_tag_t* tag = nullptr;
- exif_ifd_t* ifd;
- uint16_t item_size, size;
+ uint16_t size;
- ifd = exif_find_ifd(exif_app, ifd_nr);
+ exif_ifd_t* ifd = exif_find_ifd(exif_app, ifd_nr);
if (ifd == nullptr) {
ifd = (exif_ifd_t*) xcalloc(sizeof(*ifd), 1);
ifd->nr = ifd_nr;
tag = exif_find_tag(exif_app, ifd_nr, tag_id);
}
- item_size = exif_type_size(type);
+ uint16_t item_size = exif_type_size(type);
if ((data == nullptr) || (count < 1) || (index < 0)) {
size = 0;
static void
exif_put_coord(const int ifd_nr, const int tag_id, const double val)
{
- double vmin, vsec;
- int vint;
-
- vint = abs((int) val);
- vmin = 60.0 * (fabs(val) - vint);
- vsec = 60.0 * (vmin - floor(vmin));
+ int vint = abs((int) val);
+ double vmin = 60.0 * (fabs(val) - vint);
+ double vsec = 60.0 * (vmin - floor(vmin));
vmin = floor(vmin);
exif_put_double(ifd_nr, tag_id, 0, (double)vint);
static void
exif_write_ifd(const exif_ifd_t* ifd, const char next, gbfile* fout)
{
- gbsize_t offs;
queue* elem, *tmp;
gbfputuint16(ifd->count, fout);
- offs = gbftell(fout) + (ifd->count * 12) + 4;
+ gbsize_t offs = gbftell(fout) + (ifd->count * 12) + 4;
QUEUE_FOR_EACH(&ifd->tags, elem, tmp) {
exif_tag_t* tag = (exif_tag_t*)elem;
if (app == exif_app) {
queue* e1, *t1;
uint16_t len = 8;
- gbfile* ftmp;
exif_tag_t* tag;
exif_put_long(IFD0, IFD0_TAG_GPS_IFD_OFFS, 0, 0);
sortqueue(&ifd->tags, exif_sort_tags_cb);
}
- ftmp = gbfopen_be(nullptr, "wb", MYNAME);
+ gbfile* ftmp = gbfopen_be(nullptr, "wb", MYNAME);
ftmp->big_endian = app->fcache->big_endian;
gbfwrite((ftmp->big_endian) ? "MM" : "II", 2, 1, ftmp);
static void
exif_read()
{
- uint16_t soi;
- Waypoint* wpt;
-
- soi = gbfgetuint16(fin);
+ uint16_t soi = gbfgetuint16(fin);
is_fatal(soi != 0xFFD8, MYNAME ": Unknown image file."); /* only jpeg for now */
exif_app = exif_load_apps();
is_fatal(exif_app == nullptr, MYNAME ": No EXIF header in source file \"%s\".", fin->name);
exif_examine_app(exif_app);
- wpt = exif_waypt_from_exif_app(exif_app);
+ Waypoint* wpt = exif_waypt_from_exif_app(exif_app);
if (wpt) {
waypt_add(wpt);
}
static void
exif_wr_init(const QString& fname)
{
- uint16_t soi;
-
exif_success = 0;
exif_fout_name = fname;
fin = gbfopen_be(fname, "rb", MYNAME);
is_fatal(fin->is_pipe, MYNAME ": Sorry, this format cannot be used with pipes!");
- soi = gbfgetuint16(fin);
+ uint16_t soi = gbfgetuint16(fin);
is_fatal(soi != 0xFFD8, MYNAME ": Unknown image file.");
exif_app = exif_load_apps();
is_fatal(exif_app == nullptr, MYNAME ": No EXIF header found in source file \"%s\".", fin->name);
static void
exif_write()
{
- time_t frame;
-
exif_wpt_ref = nullptr;
if (opt_name) {
route_disp_all(nullptr, nullptr, exif_find_wpt_by_time);
waypt_disp_all(exif_find_wpt_by_time);
- frame = atoi(opt_frame);
+ time_t frame = atoi(opt_frame);
if (exif_wpt_ref == nullptr) {
warning(MYNAME ": No point with a valid timestamp found.\n");
}
if (wpt->creation_time.isValid()) {
- struct tm tm;
char buf[32];
const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = *gmtime(&tt);
+ struct tm tm = *gmtime(&tt);
tm.tm_year += 1900;
tm.tm_mon += 1;
explorist_ini_try(const char* path)
{
char* inipath;
- char* s;
xasprintf(&inipath, "%s/%s", path, "APP/Atlas.ini");
inifile = inifile_init(QString::fromUtf8(inipath), myname);
info->track_path = nullptr;
info->waypoint_path = nullptr;
- s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder"));
+ char* s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder"));
if (s) {
s = gstrsub(s, "\\", "/");
xasprintf(&info->waypoint_path, "%s/%s", path, s);
static void
f90g_track_read()
{
- Waypoint* readWaypoint;
char northSouth, eastWest, velocityMark, ttRec[TTRECORDSIZE], tempBuf[20];
int year, mon, mday, hour, min, sec, latitudeDeg, latitudeMin, longitudeDeg, longitudeMin, velocity;
- QDateTime dt;
is_fatal((track == nullptr), MYNAME "Track setup error");
for (;;) {
&& velocityMark == 'M') {
// create the Waypoint and fill it in
- readWaypoint = new Waypoint;
- dt = QDateTime(QDate(year, mon, mday), QTime(hour, min, sec), Qt::UTC);
+ Waypoint* readWaypoint = new Waypoint;
+ QDateTime dt = QDateTime(QDate(year, mon, mday), QTime(hour, min, sec), Qt::UTC);
readWaypoint->SetCreationTime(dt);
readWaypoint->latitude = (double(latitudeDeg) + double(latitudeMin)/MIN_PER_DEGREE)
while (vec->vec) {
arglist_t* ap;
- const char* res;
if (svecname.compare(vec->name, Qt::CaseInsensitive)) {
vec++;
struct arglist* args = vec->vec->get_args();
if (args) {
for (ap = args; ap->argstring; ap++) {
- const char* temp;
-
- temp = inifile_readstr(global_opts.inifile, vec->name, ap->argstring);
+ const char* temp = inifile_readstr(global_opts.inifile, vec->name, ap->argstring);
if (temp == nullptr) {
temp = inifile_readstr(global_opts.inifile, "Common filter settings", ap->argstring);
}
}
/* step 2: override settings with command-line values */
- res = strchr(vecname, ',');
+ const char* res = strchr(vecname, ',');
if (res) {
*opts = res+1;
if (args) {
for (ap = args; ap->argstring; ap++) {
- char* opt;
-
- opt = get_option(*opts, ap->argstring);
+ char* opt = get_option(*opts, ap->argstring);
if (opt) {
found = 1;
assign_option(vec->name, ap, opt);
void
free_filter_vec(Filter* filter)
{
- arglist_t* ap;
struct arglist* args = filter->get_args();
if (args) {
- for (ap = args; ap->argstring; ap++) {
+ for (arglist_t* ap = args; ap->argstring; ap++) {
if (ap->argvalptr) {
xfree(ap->argvalptr);
ap->argvalptr = *ap->argval = nullptr;
{
fl_vecs_t* vec = filter_vec_list;
while (vec->vec) {
- arglist_t* ap;
struct arglist* args = vec->vec->get_args();
if (args) {
- for (ap = args; ap->argstring; ap++) {
+ for (arglist_t* ap = args; ap->argstring; ap++) {
ap->argvalptr = nullptr;
}
}
void
disp_filter_vecs()
{
- fl_vecs_t* vec;
- arglist_t* ap;
-
- for (vec = filter_vec_list; vec->vec; vec++) {
+ for (fl_vecs_t* vec = filter_vec_list; vec->vec; vec++) {
printf(" %-20.20s %-50.50s\n",
vec->name, vec->desc);
struct arglist* args = vec->vec->get_args();
- for (ap = args; ap && ap->argstring; ap++) {
+ for (arglist_t* ap = args; ap && ap->argstring; ap++) {
if (!(ap->argtype & ARGTYPE_HIDDEN))
printf(" %-18.18s %-.50s %s\n",
ap->argstring, ap->helpstring,
void
disp_filter_vec(const char* vecname)
{
- fl_vecs_t* vec;
- arglist_t* ap;
-
- for (vec = filter_vec_list; vec->vec; vec++) {
+ for (fl_vecs_t* vec = filter_vec_list; vec->vec; vec++) {
if (case_ignore_strcmp(vec->name, vecname)) {
continue;
}
printf(" %-20.20s %-50.50s\n",
vec->name, vec->desc);
struct arglist* args = vec->vec->get_args();
- for (ap = args; ap && ap->argstring; ap++) {
+ for (arglist_t* ap = args; ap && ap->argstring; ap++) {
if (!(ap->argtype & ARGTYPE_HIDDEN))
printf(" %-18.18s %-.50s %s\n",
ap->argstring, ap->helpstring,
static void
disp_v1(const fl_vecs_t* vec)
{
- arglist_t* ap;
-
disp_help_url(vec, nullptr);
printf("\n");
struct arglist* args = vec->vec->get_args();
- for (ap = args; ap && ap->argstring; ap++) {
+ for (arglist_t* ap = args; ap && ap->argstring; ap++) {
if (!(ap->argtype & ARGTYPE_HIDDEN)) {
printf("option\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
vec->name,
static Waypoint*
parse_waypt(char* buff)
{
- char* cin, *cerr;
- int i;
+ char* cin;
struct tm tm;
- Waypoint* wpt;
- garmin_fs_p gmsd;
- wpt = new Waypoint;
- gmsd = garmin_fs_alloc(-1);
+ Waypoint* wpt = new Waypoint;
+ garmin_fs_p gmsd = garmin_fs_alloc(-1);
fs_chain_add(&wpt->fs, (format_specific_data*) gmsd);
if (gardown) {
}
memset(&tm, 0, sizeof(tm));
- cerr = strptime(buff, "%a %b %d %H:%M:%S %Y", &tm);
+ char* cerr = strptime(buff, "%a %b %d %H:%M:%S %Y", &tm);
if (cerr == nullptr) {
fatal(MYNAME ": Unable to convert date (%s)!\n", buff);
}
wpt->SetCreationTime(mkgmtime(&tm));
/* go over time stamp */
- i = 5;
+ int i = 5;
while (buff && i) {
i--;
buff = strchr(buff, ' ');
static Waypoint*
parse_trkpt(char* buff)
{
- garmin_fs_p gmsd;
- Waypoint* wpt;
-
- wpt = new Waypoint;
- gmsd = garmin_fs_alloc(-1);
+ Waypoint* wpt = new Waypoint;
+ garmin_fs_p gmsd = garmin_fs_alloc(-1);
fs_chain_add(&wpt->fs, (format_specific_data*) gmsd);
parse_line(buff, TRKPT__OFS, ";", wpt);
route_head* head = nullptr;
while ((buff = gbfgetstr(fin))) {
- char* cdata;
-
if ((line++ == 0) && fin->unicode) {
cet_convert_init(CET_CHARSET_UTF8, 1);
}
continue;
}
- cdata = cin+1;
+ char* cdata = cin+1;
while (! isspace(*cdata)) {
cdata++;
}
cdata++;
}
if (*cdata) {
- char* s;
- s = strrchr(cdata, ',');
+ char* s = strrchr(cdata, ',');
if (s) {
*s = '\0';
s = strrchr(cdata, ',');
static void
rw_init(const QString& fname)
{
- int receiver_short_length;
int receiver_must_upper = 1;
const char* receiver_charset = nullptr;
* Fortunately, getting this "wrong" only results in ugly names
* when we're using the synthesize_shortname path.
*/
- receiver_short_length = 10;
+ int receiver_short_length = 10;
switch (gps_waypt_type) { /* waypoint type as defined by jeeps */
case 0:
void
track_read()
{
- int32 ntracks;
GPS_PTrack* array;
route_head* trk_head = nullptr;
int trk_num = 0;
}
- ntracks = GPS_Command_Get_Track(portname, &array, waypt_read_cb);
+ int32 ntracks = GPS_Command_Get_Track(portname, &array, waypt_read_cb);
if (ntracks <= 0) {
return;
}
for (int i = 0; i < ntracks; i++) {
- Waypoint* wpt;
-
/*
* This is probably always in slot zero, but the Garmin
* serial spec says these can appear anywhere. Toss them
if (array[i]->no_latlon || array[i]->ishdr) {
continue;
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->longitude = array[i]->lon;
wpt->latitude = array[i]->lat;
void
route_read()
{
- int32 nroutepts;
GPS_PWay* array;
/* TODO: Fixes warning but is it right?
* RJL: No, the warning isn't right; GCC's flow analysis is broken.
*/
route_head* rte_head = nullptr;
- nroutepts = GPS_Command_Get_Route(portname, &array);
+ int32 nroutepts = GPS_Command_Get_Route(portname, &array);
// fprintf(stderr, "Routes %d\n", (int) nroutepts);
#if 1
static void
pvt2wpt(GPS_PPvt_Data pvt, Waypoint* wpt)
{
- double wptime, wptimes;
-
wpt->altitude = pvt->alt;
wpt->latitude = pvt->lat;
wpt->longitude = pvt->lon;
* 3) The number of leap seconds that offset the current UTC and GPS
* reference clocks.
*/
- wptime = 631065600.0 + pvt->wn_days * 86400.0 +
- pvt->tow
- - pvt->leap_scnds;
- wptimes = floor(wptime);
+ double wptime = 631065600.0 + pvt->wn_days * 86400.0 +
+ pvt->tow
+ - pvt->leap_scnds;
+ double wptimes = floor(wptime);
wpt->SetCreationTime(wptimes, 1000000.0 * (wptime - wptimes));
/*
static GPS_PWay
sane_GPS_Way_New()
{
- GPS_PWay way;
- way = GPS_Way_New();
+ GPS_PWay way = GPS_Way_New();
if (!way) {
fatal(MYNAME ":not enough memory\n");
}
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
Waypoint* wpt = (Waypoint*) elem;
#endif
- char* ident;
char obuf[256];
QString src;
* mkshort will do collision detection and namespace
* cleaning
*/
- ident = mkshort(mkshort_handle,
- global_opts.synthesize_shortnames ? CSTRc(src) :
- CSTRc(wpt->shortname));
+ char* ident = mkshort(mkshort_handle,
+ global_opts.synthesize_shortnames ? CSTRc(src) :
+ CSTRc(wpt->shortname));
/* Should not be a strcpy as 'ident' isn't really a C string,
* but rather a garmin "fixed length" buffer that's padded
* to the end with spaces. So this is NOT (strlen+1).
static void
waypoint_write()
{
- int n;
int32 ret;
- n = waypoint_prepare();
+ int n = waypoint_prepare();
if ((ret = GPS_Command_Send_Waypoint(portname, tx_waylist, n, waypt_write_cb)) < 0) {
fatal(MYNAME ":communication error sending wayoints..\n");
rte->alt = 0;
}
- // Garmin protocol spec says no spaces, no lowercase, etc. in a route.
- // enforce that here, since jeeps doesn't.
- //
- // This was strncpy(rte->ident, wpt->shortname, sizeof(rte->ident));
- char* d;
- d = rte->ident;
+ char* d = rte->ident;
for (auto idx : wpt->shortname) {
int c = idx.toLatin1();
if (receiver_must_upper && isalpha(c)) {
static void
track_write()
{
- int n;
-
- n = track_prepare();
+ int n = track_prepare();
GPS_Command_Send_Track(portname, tx_tracklist, n, (eraset)? 1 : 0);
for (int i = 0; i < n; i++) {
static void
course_write()
{
- int i, n_trk, n_wpt;
+ int i;
- n_wpt = waypoint_prepare();
- n_trk = track_prepare();
+ int n_wpt = waypoint_prepare();
+ int n_trk = track_prepare();
GPS_Command_Send_Track_As_Course(portname, tx_tracklist, n_trk,
tx_waylist, n_wpt, (eraset)? 1 : 0);
const gdx_info*
gdx_find_file(char** dirlist)
{
- const gdx_info* gdx;
while (dirlist && *dirlist) {
char* tbuf;
xasprintf(&tbuf, "%s/%s", *dirlist, "/Garmin/GarminDevice.xml");
mountpoint = *dirlist;
- gdx = gdx_read(tbuf);
+ const gdx_info* gdx = gdx_read(tbuf);
xfree(tbuf);
if (gdx) {
longjmp(gdx_jmp_buf, 1);
static void
fit_parse_header()
{
- int len;
- int ver;
char sig[4];
- len = gbfgetc(fin);
+ int len = gbfgetc(fin);
if (len == EOF || len < 12) {
fatal(MYNAME ": Bad header\n");
}
debug_print(1,"%s: header len=%d\n", MYNAME, len);
}
- ver = gbfgetc(fin);
+ int ver = gbfgetc(fin);
if (ver == EOF || (ver >> 4) > 2)
fatal(MYNAME ": Unsupported protocol version %d.%d\n",
ver >> 4, ver & 0xf);
static uint8_t
fit_getuint8()
{
- int val;
-
if (fit_data.len == 0) {
// fail gracefully for GARMIN Edge 800 with newest firmware, seems to write a wrong record length
// for the last record.
}
return 0;
}
- val = gbfgetc(fin);
+ int val = gbfgetc(fin);
if (val == EOF) {
fatal(MYNAME ": unexpected end of file with fit_data.len=%d\n",fit_data.len);
}
{
int local_id = header & 0x0f;
fit_message_def* def = &fit_data.message_def[local_id];
- int i;
if (def->fields) {
xfree(def->fields);
// first byte is reserved. It's usually 0 and we don't know what it is,
// but we've seen some files that are 0x40. So we just read it and toss it.
- i = fit_getuint8();
+ int i = fit_getuint8();
// second byte is endianness
def->endian = fit_getuint8();
static void
fit_parse_data(fit_message_def* def, int time_offset)
{
- fit_field_t* f;
uint32_t timestamp = fit_data.last_timestamp + time_offset;
- uint32_t val;
int32_t lat = 0x7fffffff;
int32_t lon = 0x7fffffff;
uint16_t alt = 0xffff;
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing field %d\n", MYNAME, i);
}
- f = &def->fields[i];
- val = fit_read_field(f);
+ fit_field_t* f = &def->fields[i];
+ uint32_t val = fit_read_field(f);
if (f->id == kFieldTimestamp) {
if (global_opts.debug_level >= 7) {
debug_print(7,"%s: parsing fit data: timestamp=%d\n", MYNAME, val);
static void
fit_parse_record()
{
- uint8_t header;
-
- header = fit_getuint8();
+ uint8_t header = fit_getuint8();
// high bit 7 set -> compressed message (0 for normal)
// second bit 6 set -> 0 for data message, 1 for definition message
// bit 5 -> message type specific
garmin_fs_xml_fprint(const Waypoint* waypt,
QXmlStreamWriter* writer)
{
- const char* phone, *addr;
garmin_fs_t* gmsd = GMSD_FIND(waypt);
if (gmsd == nullptr) {
}
/* Find out if there is at least one field set */
- addr = GMSD_GET(addr, "");
+ const char* addr = GMSD_GET(addr, "");
if (! *addr) {
addr = GMSD_GET(city, "");
}
addr = GMSD_GET(state, "");
}
- phone = GMSD_GET(phone_nr, "");
+ const char* phone = GMSD_GET(phone_nr, "");
if (*addr || *phone ||
(gmsd->flags.category && gmsd->category) ||
void
garmin_fs_xml_convert(const int base_tag, int tag, const QString& Qcdatastr, Waypoint* waypt)
{
- garmin_fs_t* gmsd;
-// FIXME: eliminate C string copy/use here:
+ // FIXME: eliminate C string copy/use here:
const char *cdatastr = xstrdup(Qcdatastr);
- gmsd = GMSD_FIND(waypt);
+ garmin_fs_t* gmsd = GMSD_FIND(waypt);
if (gmsd == nullptr) {
gmsd = garmin_fs_alloc(-1);
fs_chain_add(&waypt->fs, (format_specific_data*) gmsd);
} else if (global_opts.inifile != nullptr) {
// Do we have a gpsbabel.ini that maps category names to category #'s?
for (i = 0; i < 16; i++) {
- char* c;
char key[3];
// use assertion to silence gcc 7.3 warning
// warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
assert((i>=0) && (i<16));
snprintf(key, sizeof(key), "%d", i + 1);
- c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key);
+ char* c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key);
if ((c != nullptr) && (case_ignore_strcmp(c, category_name) == 0)) {
cat = (1 << i);
break;
garmin_fs_merge_category(const char* category_name, Waypoint* waypt)
{
uint16_t cat;
- garmin_fs_t* gmsd;
// Attempt to get a textual category name to a category number.
if (!garmin_fs_convert_category(category_name, &cat)) {
return 0;
}
- gmsd = GMSD_FIND(waypt);
+ garmin_fs_t* gmsd = GMSD_FIND(waypt);
cat = cat | (GMSD_GET(category, 0));
if (gmsd == nullptr) {
gpi_read_lc_string_old(char* languagecode, short* length)
{
char lc[3];
- short len;
gbfread(lc, 1, 2, fin);
lc[2] = '\0';
- len = gbfgetint16(fin);
+ short len = gbfgetint16(fin);
if ((lc[0] < 'A') || (lc[0] > 'Z') || (lc[1] < 'A') || (lc[1] > 'Z')) {
fatal(MYNAME ": Invalid language code %s!\n", lc);
static char*
gpi_read_string_old(const char* field)
{
- int l0;
char* res = nullptr;
- l0 = gbfgetint16(fin);
+ int l0 = gbfgetint16(fin);
if (l0 > 0) {
- char first;
-
- first = gbfgetc(fin);
+ char first = gbfgetc(fin);
if (first == 0) {
short l1;
short l2;
static void
read_poi_list(const int sz)
{
- int pos, i;
+ int i;
- pos = gbftell(fin);
+ int pos = gbftell(fin);
#ifdef GPI_DBG
PP;
dbginfo("> reading poi list (-> %1$x / %1$d )\n", pos + sz);
static void
read_poi_group(const int sz, const int tag)
{
- int pos;
-
- pos = gbftell(fin);
+ int pos = gbftell(fin);
#ifdef GPI_DBG
PP;
dbginfo("> reading poi group (-> %1$x / %1$d)\n", pos + sz);
#endif
if (tag == 0x80009) {
- int subsz;
-
PP;
- subsz = gbfgetint32(fin); /* ? offset to category data ? */
+ int subsz = gbfgetint32(fin); /* ? offset to category data ? */
#ifdef GPI_DBG
dbginfo("group sublen = %d (-> %x / %d)\n", subsz, pos + subsz + 4, pos + subsz + 4);
#else
read_tag(const char* caller, const int tag, Waypoint* wpt)
{
Q_UNUSED(caller);
- int pos, sz, dist;
+ int dist;
double speed;
short mask;
QString str;
char* cstr;
garmin_fs_t* gmsd;
- sz = gbfgetint32(fin);
- pos = gbftell(fin);
+ int sz = gbfgetint32(fin);
+ int pos = gbftell(fin);
#ifdef GPI_DBG
PP;
static void
write_string(const char* str, const char long_format)
{
- int len;
-
- len = strlen(str);
+ int len = strlen(str);
if (long_format) {
gbfputint32(len + 4, fout);
gbfwrite("EN", 1, 2, fout);
static writer_data_t*
wdata_alloc()
{
- writer_data_t* res;
-
- res = (writer_data_t*) xcalloc(1, sizeof(*res));
+ writer_data_t* res = (writer_data_t*) xcalloc(1, sizeof(*res));
QUEUE_INIT(&res->Q);
waypt_init_bounds(&res->bds);
wdata_check(writer_data_t* data)
{
queue* elem, *tmp;
- double center_lat, center_lon;
+ double center_lon;
if ((data->ct <= WAYPOINTS_PER_BLOCK) ||
/* avoid endless loop for points (more than WAYPOINTS_PER_BLOCK)
/* compute the (mean) center of current bounds */
- center_lat = center_lon = 0;
+ double center_lat = center_lon = 0;
QUEUE_FOR_EACH(&data->Q, elem, tmp) {
Waypoint* wpt = (Waypoint*) elem;
center_lat += wpt->latitude;
QUEUE_FOR_EACH(&data->Q, elem, tmp) {
Waypoint* wpt = (Waypoint*) elem;
- gpi_waypt_t* dt;
garmin_fs_t* gmsd;
- QString str;
res += 12; /* tag/sz/sub-sz */
res += 19; /* poi fixed size */
res += 10; /* tag(4) */
}
- dt = (gpi_waypt_t*) xcalloc(1, sizeof(*dt));
+ gpi_waypt_t* dt = (gpi_waypt_t*) xcalloc(1, sizeof(*dt));
wpt->extra_data = dt;
if (alerts) {
#if NEW_STRINGS
-// examine closely.
- const char* pos;
int pidx;
if ((pidx = wpt->shortname.indexOf('@')) != -1) {
- pos = CSTR(wpt->shortname.mid(pidx));
+ const char* pos = CSTR(wpt->shortname.mid(pidx));
#else
char* pos;
if ((pos = strchr(wpt->shortname, '@'))) {
}
}
- str = QString();
+ QString str = QString();
if (opt_descr) {
if (!wpt->description.isEmpty()) {
str = wpt->description;
gbfputc(data->alert, fout);
QUEUE_FOR_EACH(&data->Q, elem, tmp) {
- QString str;
- int s0, s1;
+ int s1;
Waypoint* wpt = (Waypoint*)elem;
gpi_waypt_t* dt = (gpi_waypt_t*) wpt->extra_data;
- str = wpt->description;
+ QString str = wpt->description;
if (str.isEmpty()) {
str = wpt->notes;
}
gbfputint32(0x80002, fout);
- s0 = s1 = 19 + strlen(STRFROMUNICODE(wpt->shortname));
+ int s0 = s1 = 19 + strlen(STRFROMUNICODE(wpt->shortname));
if (! opt_hide_bitmap) {
s0 += 10; /* tag(4) */
}
static void
write_category(const char*, const unsigned char* image, const int image_sz)
{
- int sz;
-
- sz = wdata_compute_size(wdata);
+ int sz = wdata_compute_size(wdata);
sz += 8; /* string header */
sz += strlen(STRFROMUNICODE(QString::fromUtf8(opt_cat)));
static void
enum_waypt_cb(const Waypoint* ref)
{
- Waypoint* wpt;
queue* elem, *tmp;
QUEUE_FOR_EACH(&wdata->Q, elem, tmp) {
}
}
- wpt = new Waypoint(*ref);
+ Waypoint* wpt = new Waypoint(*ref);
if (*opt_unique == '1') {
wpt->shortname = mkshort(short_h, wpt->shortname);
static void
load_bitmap_from_file(const char* fname, unsigned char** data, int* data_sz)
{
- gbfile* f;
int i, sz;
int dest_bpp;
int src_line_sz, dest_line_sz;
gpi_bitmap_header_t* dest_h;
unsigned char* ptr;
- f = gbfopen_le(fname, "rb", MYNAME);
+ gbfile* f = gbfopen_le(fname, "rb", MYNAME);
is_fatal(gbfgetint16(f) != 0x4d42, MYNAME ": No BMP image.");
/* read a standard bmp file header */
unsigned char* p = ptr;
for (j = 0; j < src_h.width; j++) {
- int color;
- color = (int32_t)gbfgetint16(f) | (gbfgetc(f) << 16);
+ int color = (int32_t)gbfgetint16(f) | (gbfgetc(f) << 16);
le_write32(p, color);
p += 4;
}
static int find_flag = 0;
icon_mapping_t* i;
int def_icon = DEFAULT_ICON_VALUE;
- int n;
if (desc.isNull()) {
return def_icon;
* If we were given a numeric icon number as a description
* (i.e. 8255), just return that.
*/
- n = desc.toInt();
+ int n = desc.toInt();
if (n) {
return n;
}
gt_country_code_t* x = >_country_codes[0];
if (country.isEmpty()) {
- const char* test;
if (shortname == nullptr) {
return nullptr;
}
default:
return nullptr;
}
- test = gt_get_icao_country(res);
+ const char* test = gt_get_icao_country(res);
if (test != nullptr) {
return res;
} else {
const char*
gt_get_mps_datum_name(const int datum_index)
{
- const char* result;
-
- result = GPS_Math_Get_Datum_Name(datum_index);
+ const char* result = GPS_Math_Get_Datum_Name(datum_index);
for (datum_mapping_t* d = gt_mps_datum_names; (d->jeeps_name); d++)
if (QString::compare(result, d->jeeps_name, Qt::CaseInsensitive) == 0) {
int
gt_lookup_datum_index(const char* datum_str, const QString& module)
{
- int result;
const char* name = datum_str;
for (datum_mapping_t* d = gt_mps_datum_names; (d->jeeps_name); d++) {
}
}
- result = GPS_Lookup_Datum_Index(name);
+ int result = GPS_Lookup_Datum_Index(name);
// Didn't get a hit? Try again after modifying the lookup.
if (result < 0) {
static void
init_date_and_time_format()
{
- const char* f;
- const char* c;
-
- f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT);
+ const char* f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT);
date_time_format = convert_human_date_format(f);
date_time_format = xstrappend(date_time_format, " ");
f = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT);
- c = convert_human_time_format(f);
+ const char* c = convert_human_time_format(f);
date_time_format = xstrappend(date_time_format, c);
xfree((void*) c);
}
static void
enum_waypt_cb(const Waypoint* wpt)
{
- garmin_fs_p gmsd;
- int wpt_class;
-
- gmsd = GMSD_FIND(wpt);
- wpt_class = GMSD_GET(wpt_class, 0);
+ garmin_fs_p gmsd = GMSD_FIND(wpt);
+ int wpt_class = GMSD_GET(wpt_class, 0);
if (wpt_class < 0x80) {
if (gtxt_flags.enum_waypoints) { /* enumerate only */
waypoints++;
{
int valid = 1;
double lat, lon, north, east;
- char latsig, lonsig;
- double latmin, lonmin, latsec, lonsec;
- int latint, lonint, zone;
+ int zone;
char map[3], zonec;
convert_datum(wpt, &lat, &lon);
/* !ToDo! generate common code for calculating of degrees, minutes and seconds */
/* ----------------------------------------------------------------------------*/
- latsig = lat < 0 ? 'S':'N';
- lonsig = lon < 0 ? 'W':'E';
- latint = abs((int) lat);
- lonint = abs((int) lon);
- latmin = 60.0 * (fabs(lat) - latint);
- lonmin = 60.0 * (fabs(lon) - lonint);
- latsec = 60.0 * (latmin - floor(latmin));
- lonsec = 60.0 * (lonmin - floor(lonmin));
+ char latsig = lat < 0 ? 'S':'N';
+ char lonsig = lon < 0 ? 'W':'E';
+ int latint = abs((int) lat);
+ int lonint = abs((int) lon);
+ double latmin = 60.0 * (fabs(lat) - latint);
+ double lonmin = 60.0 * (fabs(lon) - lonint);
+ double latsec = 60.0 * (latmin - floor(latmin));
+ double lonsec = 60.0 * (lonmin - floor(lonmin));
switch (grid_index) {
static void
print_categories(uint16_t categories)
{
- int count;
char* c;
if (categories == 0) {
return;
}
- count = 0;
+ int count = 0;
for (int i = 0; i < 16; i++) {
if ((categories & 1) != 0) {
if (global_opts.inifile != nullptr) {
print_course(const Waypoint* A, const Waypoint* B) /* seems to be okay */
{
if ((A != nullptr) && (B != nullptr) && (A != B)) {
- int course;
- course = si_round(waypt_course(A, B));
+ int course = si_round(waypt_course(A, B));
gbfprintf(fout, "%d%c true", course, kDegreeSymbol);
}
}
static void
print_speed(double* distance, time_t* time)
{
- int idist;
double dist = *distance;
const char* unit;
} else {
unit = "kph";
}
- idist = si_round(dist);
+ int idist = si_round(dist);
if ((*time != 0) && (idist > 0)) {
double speed = MPS_TO_KPH(dist / (double)*time);
static void
print_string(const char* fmt, const char* string)
{
- char* buff;
-
- buff = xstrdup(string);
+ char* buff = xstrdup(string);
/* remove unwanted characters from source string */
for (char* c = buff; *c; c++) {
if (iscntrl(*c)) {
static void
write_waypt(const Waypoint* wpt)
{
- unsigned char wpt_class;
- garmin_fs_p gmsd;
const char* wpt_type;
- const char* dspl_mode;
- const char* country;
- double x;
- int i, icon;
- gmsd = GMSD_FIND(wpt);
+ garmin_fs_p gmsd = GMSD_FIND(wpt);
- i = GMSD_GET(display, 0);
+ int i = GMSD_GET(display, 0);
if (i > GT_DISPLAY_MODE_MAX) {
i = 0;
}
- dspl_mode = gt_display_mode_names[i];
+ const char* dspl_mode = gt_display_mode_names[i];
- wpt_class = GMSD_GET(wpt_class, 0);
+ unsigned char wpt_class = GMSD_GET(wpt_class, 0);
if (wpt_class <= gt_waypt_class_map_line) {
wpt_type = gt_waypt_class_names[wpt_class];
} else {
}
gbfprintf(fout, "\t");
- x = WAYPT_GET(wpt, depth, unknown_alt);
+ double x = WAYPT_GET(wpt, depth, unknown_alt);
if (x != unknown_alt) {
print_distance(x, 1, 0, 1);
}
gbfprintf(fout, "Unknown\t"); /* Color is fixed: Unknown */
- icon = GMSD_GET(icon, -1);
+ int icon = GMSD_GET(icon, -1);
if (icon == -1) {
icon = gt_find_icon_number_from_desc(wpt->icon_descr, GDB);
}
print_string("%s\t", GMSD_GET(facility, ""));
print_string("%s\t", GMSD_GET(city, ""));
print_string("%s\t", GMSD_GET(state, ""));
- country = gt_get_icao_country(GMSD_GET(cc, ""));
+ const char* country = gt_get_icao_country(GMSD_GET(cc, ""));
print_string("%s\t", (country != nullptr) ? country : "");
print_date_and_time(wpt->GetCreationTime().toTime_t(), 0);
if (wpt->HasUrlLink()) {
{
const Waypoint* prev = cur_info->prev_wpt;
time_t delta;
- double dist, depth;
+ double dist;
gbfprintf(fout, "Trackpoint\t");
}
gbfprintf(fout, "\t");
- depth = WAYPT_GET(wpt, depth, unknown_alt);
+ double depth = WAYPT_GET(wpt, depth, unknown_alt);
if (depth != unknown_alt) {
print_distance(depth, 1, 0, 1);
}
if (prev != nullptr) {
- float temp;
gbfprintf(fout, "\t");
delta = wpt->GetCreationTime().toTime_t() - prev->GetCreationTime().toTime_t();
- temp = WAYPT_GET(wpt, temperature, -999);
+ float temp = WAYPT_GET(wpt, temperature, -999);
if (temp != -999) {
print_temperature(temp);
}
static void
garmin_txt_wr_init(const QString& fname)
{
- const char* grid_str;
-
memset(>xt_flags, 0, sizeof(gtxt_flags));
fout = gbfopen(fname, "wb", MYNAME);
}
datum_str = get_option_val(opt_datum, nullptr);
- grid_str = get_option_val(opt_grid, nullptr);
+ const char* grid_str = get_option_val(opt_grid, nullptr);
grid_index = grid_lat_lon_dmm;
if (grid_str != nullptr) {
static void
garmin_txt_write()
{
- char* grid_str, *c;
- const char* datum_str;
+ char* c;
- grid_str = xstrdup(gt_get_mps_grid_longname(grid_index, MYNAME));
+ char* grid_str = xstrdup(gt_get_mps_grid_longname(grid_index, MYNAME));
while ((c = strchr(grid_str, '*'))) {
*c = kDegreeSymbol; /* degree sign */
}
gbfprintf(fout, "Grid\t%s\r\n", grid_str);
xfree(grid_str);
- datum_str = gt_get_mps_datum_name(datum_index);
+ const char* datum_str = gt_get_mps_datum_name(datum_index);
gbfprintf(fout, "Datum\t%s\r\n\r\n", datum_str);
waypoints = 0;
parse_date_and_time(char* str, time_t* value)
{
struct tm tm;
- char* cerr, *cin;
memset(&tm, 0, sizeof(tm));
- cin = lrtrim(str);
+ char* cin = lrtrim(str);
if (*cin == '\0') {
return 0;
}
- cerr = strptime(cin, date_time_format, &tm);
+ char* cerr = strptime(cin, date_time_format, &tm);
if (cerr == nullptr) {
cerr = strptime(cin, "%m/%d/%Y %I:%M:%S %p", &tm);
is_fatal(cerr == nullptr, MYNAME ": Invalid date or/and time \"%s\" at line %d!", cin, current_line);
char buff[256];
uint16_t val;
uint16_t res = 0;
- char* cin, *cx;
+ char* cx;
if (*str == '\0') {
return 0;
}
strncpy(buff, str, sizeof(buff));
- cin = lrtrim(buff);
+ char* cin = lrtrim(buff);
if (*cin == '\0') {
return 0;
}
static void
bind_fields(const header_type ht)
{
- int i;
- char* fields, *c;
-
is_fatal((grid_index < 0) || (datum_index < 0), MYNAME ": Incomplete or invalid file header!");
if (header_ct[unknown_header] <= 0) {
/* make a copy of headers[ht], uppercase, replace "\t" with "\0" */
- i = strlen(headers[ht]);
- fields = (char*) xmalloc(i + 2);
+ int i = strlen(headers[ht]);
+ char* fields = (char*) xmalloc(i + 2);
strcpy(fields, headers[ht]);
strcat(fields, "\t");
- c = strupper(fields);
+ char* c = strupper(fields);
while ((c = strchr(c, '\t'))) {
*c++ = '\0';
}
for (i = 0; i < header_ct[unknown_header]; i++) {
- char* name;
- int field_no;
- name = header_lines[ht][i] = header_lines[unknown_header][i];
+ char* name = header_lines[ht][i] = header_lines[unknown_header][i];
header_lines[unknown_header][i] = nullptr;
c = fields;
- field_no = 1;
+ int field_no = 1;
while (*c) {
if (strcmp(c, name) == 0) {
header_fields[ht][i] = field_no;
{
char* str;
int column = -1;
- Waypoint* wpt;
bind_fields(waypt_header);
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
garmin_fs_p gmsd = garmin_fs_alloc(-1);
fs_chain_add(&wpt->fs, (format_specific_data*) gmsd);
{
char* str;
int column = -1;
- route_head* rte;
- rte = route_head_alloc();
+ route_head* rte = route_head_alloc();
bind_fields(route_header);
while ((str = csv_lineparse(nullptr, "\t", "", column++))) {
{
char* str;
int column = -1;
- route_head* trk;
bind_fields(track_header);
- trk = route_head_alloc();
+ route_head* trk = route_head_alloc();
while ((str = csv_lineparse(nullptr, "\t", "", column++))) {
int field_no = header_fields[track_header][column];
switch (field_no) {
{
char* str;
int column = -1;
- Waypoint* wpt;
bind_fields(trkpt_header);
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
while ((str = csv_lineparse(nullptr, "\t", "", column++))) {
- int field_no;
double x;
if (! *str) {
continue;
}
- field_no = header_fields[trkpt_header][column];
+ int field_no = header_fields[trkpt_header][column];
switch (field_no) {
case 1:
parse_coordinates(str, datum_index, grid_index,
current_line = 0;
while ((buff = gbfgetstr(fin))) {
- char* cin;
-
if ((current_line++ == 0) && fin->unicode) {
cet_convert_init(CET_CHARSET_UTF8, 1);
}
- cin = lrtrim(buff);
+ char* cin = lrtrim(buff);
if (*cin == '\0') {
continue;
}
static void
format_garmin_xt_decrypt_trk_blk(int Count, uint8_t TrackBlock[])
{
- uint8_t i,j = 12;
+ uint8_t j = 12;
while (j<(Count-1)) {
- for (i = j; i < Count; i++) {
+ for (uint8_t i = j; i < Count; i++) {
TrackBlock[i] = TrackBlock[i] >> 1;
if (i<(Count)) {
TrackBlock[i] = TrackBlock[i] + (TrackBlock[i+1] % 2) * 128;
static void
format_garmin_xt_decomp_trk_blk(uint8_t ii, uint8_t TrackBlock[], double* Ele, double* Lat, double* Lon, uint32_t* Time)
{
- uint16_t PrevEleW;
-
//printf("%d %d %d %d %d %d\n", TrackBlock[0], TrackBlock[1], TrackBlock[2], TrackBlock[3], TrackBlock[4], TrackBlock[5]);
- PrevEleW = TrackBlock[(ii - 1) * 12 + 1 ];
+ uint16_t PrevEleW = TrackBlock[(ii - 1) * 12 + 1 ];
PrevEleW = PrevEleW << 8;
PrevEleW = PrevEleW + TrackBlock[(ii - 1) * 12 ];
*Ele = (double)PrevEleW * GARMIN_XT_ELE - 1500;
static void
format_garmin_xt_decomp_last_ele(uint8_t ii, double* PrevEle, uint8_t TrackBlock[])
{
- uint16_t PrevEleW;
-
- PrevEleW = TrackBlock[ii - 1];
+ uint16_t PrevEleW = TrackBlock[ii - 1];
PrevEleW = PrevEleW << 8;
PrevEleW = PrevEleW + TrackBlock[ii - 2];
*PrevEle = (double)PrevEleW * GARMIN_XT_ELE - 1500;
int Count = 0; // Used to obtain number of read bytes
int TracksCompleted = 0; // Number of processed tracks
uint8_t TrackBlock[STRK_BLOCK_SIZE + 1]; // File Block
- uint8_t ii; // temp variable
double Lat = 0, Lon = 0; // wpt data
double PrevLat = 0, PrevLon = 0, PrevEle = 0; // wpt data
uint32_t Time = 0; // wpt data
- int FirstCoo;
uint8_t trk_color = 0xff;
// Skip 12 bytes from the BOF
// Process all tracks one by one
while ((TracksCompleted < NumberOfTracks) && (!gbfeof(fin))) {
- route_head* tmp_track;
Waypoint* wpt;
- char* trk_name;
- trk_name = (char*) xmalloc(30);
+ char* trk_name = (char*) xmalloc(30);
// Generate Track Header
uint16_t trackbytes = format_garmin_xt_rd_st_attrs(trk_name, &trk_color) - 50; // Bytes in track
- tmp_track = route_head_alloc();
+ route_head* tmp_track = route_head_alloc();
// update track color
tmp_track->line_color.bbggrr = colors[trk_color];
tmp_track->line_color.opacity = 255;
track_add_head(tmp_track);
// This is the 1st coordinate of the track
- FirstCoo = TRUE;
+ int FirstCoo = TRUE;
while (trackbytes>0) {
if (trackbytes>=STRK_BLOCK_SIZE) {
Count = gbfread(&TrackBlock, DATABLOCKSIZE, STRK_BLOCK_SIZE, fin);
format_garmin_xt_decrypt_trk_blk(Count, TrackBlock);
// process each track point in the loaded TrackBlock
- for (ii=1; ii <= ((Count-1) / 12); ii++) {
+ for (uint8_t ii = 1; ii <= ((Count-1) / 12); ii++) {
// decompose loaded track block part (track point)
format_garmin_xt_decomp_trk_blk(ii, TrackBlock, &PrevEle, &Lat, &Lon, &Time);
static void
format_garmin_xt_proc_atrk()
{
- Waypoint* wpt;
int method = 0;
unsigned char buf[3];
- int32_t num_trackpoints;
// get the option for the processing the track name
if (opt_trk_header) {
// We think the word at offset 0xc is the trackpoint count.
gbfseek(fin, 12, SEEK_SET);
- num_trackpoints = gbfgetuint32(fin);
+ int32_t num_trackpoints = gbfgetuint32(fin);
while (num_trackpoints--) {
uint16_t block = gbfgetuint16(fin);
double AltF = (double)uu * GARMIN_XT_ELE - 1500;
//create new waypoint
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
//populate wpt;
wpt->latitude = LatF*180/16777216; /* Degrees */
static int
gzapi_seek(gbfile* self, int32_t offset, int whence)
{
- int result;
-
assert(whence != SEEK_END);
if ((whence == SEEK_CUR) && (self->back != -1)) {
offset--;
}
- result = gzseek(self->handle.gz, offset, whence);
+ int result = gzseek(self->handle.gz, offset, whence);
self->back = -1;
if (result < 0) {
if ((result < 0) || ((gbsize_t)result < members)) {
int errnum;
- const char* errtxt;
- errtxt = gzerror(self->handle.gz, &errnum);
+ const char* errtxt = gzerror(self->handle.gz, &errnum);
/* Workaround for zlib bug: buffer error on empty files */
if ((errnum == Z_BUF_ERROR) && (gztell(self->handle.gz) == 0)) {
static gbsize_t
gzapi_tell(gbfile* self)
{
- gbsize_t result;
-
- result = gztell(self->handle.gz);
+ gbsize_t result = gztell(self->handle.gz);
if (self->back != -1) {
result--;
}
static int
stdapi_seek(gbfile* self, int32_t offset, int whence)
{
- int result;
gbsize_t pos = 0;
if (whence != SEEK_SET) {
pos = ftell(self->handle.std);
}
- result = fseek(self->handle.std, offset, whence);
+ int result = fseek(self->handle.std, offset, whence);
if (result != 0) {
switch (whence) {
case SEEK_CUR:
static gbsize_t
memapi_read(void* buf, const gbsize_t size, const gbsize_t members, gbfile* self)
{
- gbsize_t count;
gbsize_t result = (self->memlen - self->mempos) / size;
if (result > members) {
result = members;
}
- count = result * size;
+ gbsize_t count = result * size;
if (count) {
memcpy(buf, self->handle.mem + self->mempos, count);
self->mempos += count;
static gbsize_t
memapi_write(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* self)
{
- gbsize_t count;
-
if ((size == 0) && (members == 0)) { /* truncate stream */
self->memlen = self->mempos;
return 0;
}
- count = size * members;
+ gbsize_t count = size * members;
if (self->mempos + count > self->memsz) {
self->memsz = ((self->mempos + count + 4095) / 4096) * 4096;
gbfile*
gbfopen(const QString& filename, const char* mode, const char* module)
{
- gbfile* file;
- const char* m;
- int len;
-
- file = (gbfile*) xcalloc(1, sizeof(*file));
+ gbfile* file = (gbfile*) xcalloc(1, sizeof(*file));
file->module = xstrdup(module);
file->mode = 'r'; // default
file->back = -1;
file->memapi = (filename == nullptr);
- for (m = mode; *m; m++) {
+ for (const char* m = mode; *m; m++) {
switch (tolower(*m)) {
case 'r':
file->mode = 'r';
file->is_pipe = (filename == "-");
/* Do we have a '.gz' extension in the filename ? */
- len = strlen(file->name);
+ int len = strlen(file->name);
if ((len > 3) && (case_ignore_strcmp(&file->name[len-3], ".gz") == 0)) {
#if !ZLIB_INHIBITED
/* force gzipped files on output */
gbfile*
gbfopen_be(const QString& filename, const char* mode, const char* module)
{
- gbfile* result;
-
- result = gbfopen(filename, mode, module);
+ gbfile* result = gbfopen(filename, mode, module);
result->big_endian = 1;
return result;
gbfprintf(gbfile* file, const char* format, ...)
{
va_list args;
- int result;
va_start(args, format);
- result = gbvfprintf(file, format, args);
+ int result = gbvfprintf(file, format, args);
va_end(args);
return result;
int
gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file)
{
- unsigned int result;
-
- result = file->filewrite(buf, size, members, file);
+ unsigned int result = file->filewrite(buf, size, members, file);
if (result != members) {
fatal("%s: Could not write %lld bytes to %s (result %d)!\n",
file->module,
char*
gbfgetcstr_old(gbfile* file)
{
- char* result;
int len = 0;
char* str = file->buff;
len++;
}
- result = (char*) xmalloc(len + 1);
+ char* result = (char*) xmalloc(len + 1);
if (len > 0) {
memcpy(result, str, len);
}
for (;;) {
char buff[8];
- int clen;
- int c0, c1;
- c0 = gbfgetc(file);
+ int c0 = gbfgetc(file);
if ((c0 == EOF) && (len == 0)) {
return nullptr;
}
- c1 = gbfgetc(file);
+ int c1 = gbfgetc(file);
if ((c1 == EOF) && (len == 0)) {
return nullptr;
}
break;
}
- clen = cet_ucs4_to_utf8(buff, sizeof(buff), c0);
+ int clen = cet_ucs4_to_utf8(buff, sizeof(buff), c0);
if (clen < 1) {
Warning() << "Malformed UCS character" << c0 << "found.";
return nullptr;
} else if (c == '\n') {
break;
} else if (((c == 0xFE) || (c == 0xFF)) && (! file->unicode_checked)) {
- int cx;
int c1 = gbfgetc(file);
if (c1 != EOF) {
- cx = c | (c1 << 8);
+ int cx = c | (c1 << 8);
if (cx == 0xFEFF) {
file->unicode = 1;
file->big_endian = 0;
int gbser_setup(void* handle, const char* spec)
{
unsigned arg[] = { 4800, 8, 0, 1 };
- unsigned int ap;
- for (ap = 0; ap < sizeof(arg) / sizeof(arg[0]); ap++) {
+ for (unsigned int ap = 0; ap < sizeof(arg) / sizeof(arg[0]); ap++) {
unsigned t = 0;
int pl;
while (isspace(*spec)) {
int gbser_readc(void* handle)
{
unsigned char buf;
- int rc;
- rc = gbser_read(handle, &buf, 1);
+ int rc = gbser_read(handle, &buf, 1);
if (rc > 0) {
return buf;
} else if (rc == 0) {
int gbser_readc_wait(void* handle, unsigned ms)
{
unsigned char buf;
- int rc;
- rc = gbser_read_wait(handle, &buf, 1, ms);
+ int rc = gbser_read_wait(handle, &buf, 1, ms);
if (rc > 0) {
return buf;
} else if (rc == 0) {
) {
strncpy(obuf, comname, len);
} else {
- size_t l;
snprintf(obuf, len, DEV_PREFIX "%s", comname);
- l = strlen(obuf);
+ size_t l = strlen(obuf);
if (obuf[l - 1] == ':') {
obuf[l - 1] = '\0';
}
*/
void* gbser_init(const char* port_name)
{
- HANDLE comport;
gbser_handle* h = (gbser_handle*) xcalloc(1, sizeof(*h));
const char* xname = fix_win_serial_name(port_name);
h->magic = MYMAGIC;
- comport = CreateFileA(xname, GENERIC_READ | GENERIC_WRITE,
- 0, NULL, OPEN_EXISTING, 0, NULL);
+ HANDLE comport = CreateFileA(xname, GENERIC_READ | GENERIC_WRITE,
+ 0, NULL, OPEN_EXISTING, 0, NULL);
if (comport == INVALID_HANDLE_VALUE) {
goto failed;
}
} else {
hp_time tv;
- double time_left;
- DWORD err, nread;
+ DWORD nread;
get_time(&tv);
if (rc = set_rx_timeout(h, *ms), rc) {
return rc;
if (!ReadFile(h->comport, h->inbuf + h->inbuf_used,
want - h->inbuf_used,
&nread, NULL)) {
- err = GetLastError();
+ DWORD err = GetLastError();
if (err != ERROR_COUNTER_TIMEOUT && err != ERROR_TIMEOUT) {
return gbser_ERROR;
}
}
h->inbuf_used += nread;
- time_left = *ms - elapsed(&tv);
+ double time_left = *ms - elapsed(&tv);
*ms = time_left < 0 ? 0 : (unsigned) time_left;
}
bp[pos] = '\0';
for (;;) {
signed time_left = ms - elapsed(&tv);
- int c;
if (time_left <= 0) {
return gbser_TIMEOUT;
}
- c = gbser_readc_wait(handle, time_left);
+ int c = gbser_readc_wait(handle, time_left);
if (c == gbser_ERROR) {
return c;
} else if (c == eol) {
{
// char* res = NULL;
QString res;
- int count;
- count = FREAD_i32;
+ int count = FREAD_i32;
while (count > 0) {
QString str = fread_cstr();
static Waypoint*
gdb_reader_find_waypt(const Waypoint* wpt, const char exact)
{
- Waypoint* res;
- res = gdb_find_wayptq(&wayptq_in, wpt, exact);
+ Waypoint* res = gdb_find_wayptq(&wayptq_in, wpt, exact);
if (res == nullptr) {
res = gdb_find_wayptq(&wayptq_in_hidden, wpt, exact);
}
static Waypoint*
gdb_add_route_waypt(route_head* rte, Waypoint* ref, const int wpt_class)
{
- Waypoint* tmp, *res;
- int turn_point;
-
- tmp = gdb_reader_find_waypt(ref, 1);
+ Waypoint* tmp = gdb_reader_find_waypt(ref, 1);
if (tmp == nullptr) {
- double dist;
-
tmp = find_waypt_by_name(ref->shortname);
if (tmp == nullptr) {
route_add_wpt(rte, ref);
/* At this point we have found a waypoint with same name,
but probably from another data stream. Check coordinates!
*/
- dist = radtometers(gcdist(
- RAD(ref->latitude), RAD(ref->longitude),
- RAD(tmp->latitude), RAD(tmp->longitude)));
+ double dist = radtometers(gcdist(
+ RAD(ref->latitude), RAD(ref->longitude),
+ RAD(tmp->latitude), RAD(tmp->longitude)));
if (fabs(dist) > 100) {
warning(MYNAME ": Route point mismatch!\n");
}
}
- res = nullptr;
- turn_point = (gdb_roadbook && (wpt_class > gt_waypt_class_map_point) && !tmp->description.isEmpty());
+ Waypoint* res = nullptr;
+ int turn_point = (gdb_roadbook && (wpt_class > gt_waypt_class_map_point) && !tmp->description.isEmpty());
if (turn_point || (gdb_via == 0) || (wpt_class < gt_waypt_class_map_point)) {
res = new Waypoint(*tmp);
route_add_wpt(rte, res);
read_file_header()
{
char buf[128];
- int i, reclen;
/*
We are beginning with a simple binary read.
*/
is_fatal(strcmp(buf, "MsRcf") != 0, MYNAME ": Invalid file \"%s\"!", fin->name);
- reclen = FREAD_i32;
+ int reclen = FREAD_i32;
Q_UNUSED(reclen);
- i = FREAD_STR(buf);
+ int i = FREAD_STR(buf);
Q_UNUSED(i);
is_fatal(buf[0] != 'D', MYNAME ": Invalid file \"%s\"!", fin->name);
res->description = l.url_;
}
} else { // if (gdb_ver >= GDB_VER_3)
- int url_ct;
waypt_flag = 0;
FREAD(buf, 5); /* instruction depended */
res->description = FREAD_CSTR_AS_QSTR; /* instruction */
- url_ct = FREAD_i32;
+ int url_ct = FREAD_i32;
for (int i = url_ct; (i); i--) {
QString str = FREAD_CSTR_AS_QSTR;
if (!str.isEmpty()) {
static route_head*
read_route()
{
- route_head* rte;
- int points, warnings, links;
char buf[128];
bounds bounds;
rte_ct++;
- warnings = 0;
+ int warnings = 0;
- rte = route_head_alloc();
+ route_head* rte = route_head_alloc();
rte->rte_name = fread_cstr();
FREAD(buf, 1); /* display/autoname - 1 byte */
}
}
- links = 0;
- points = FREAD_i32;
+ int links = 0;
+ int points = FREAD_i32;
#if GDB_DEBUG
DBG(GDB_DBG_RTE, 1)
#endif
for (int i = 0; i < points; i++) {
- int wpt_class;
char buf[128];
- garmin_ilink_t* il_root, *il_anchor;
- Waypoint* wpt;
-
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
rtept_ct++;
wpt->shortname = fread_cstr(); /* shortname */
- wpt_class = FREAD_i32; /* waypoint class */
+ int wpt_class = FREAD_i32; /* waypoint class */
FREAD_STR(buf); /* country code */
FREAD(buf, 18 + 4); /* subclass part 1-3 / unknown */
}
links = FREAD_i32;
- il_anchor = nullptr;
- il_root = nullptr;
+ garmin_ilink_t* il_anchor = nullptr;
+ garmin_ilink_t* il_root = nullptr;
#if GDB_DEBUG
DBG(GDB_DBG_RTE, links)
printf(MYNAME "-rte_pt \"%s\" (%d): %d interlink step(s)\n",
static route_head*
read_track()
{
- route_head* res;
- int points;
char dummy;
- int color_idx;
trk_ct++;
- res = route_head_alloc();
+ route_head* res = route_head_alloc();
res->rte_name = fread_cstr();
// res->rte_num = trk_ct;
FREAD(&dummy, 1); /* display - 1 byte */
- color_idx = FREAD_i32; /* color - 1 dword */
+ int color_idx = FREAD_i32; /* color - 1 dword */
res->line_color.bbggrr = gt_color_value(color_idx);
- points = FREAD_i32;
+ int points = FREAD_i32;
for (int index = 0; index < points; index++) {
Waypoint* wpt = new Waypoint;
static void
read_data()
{
- gbfile* fsave;
int incomplete = 0; /* number of incomplete reads */
for (;;) {
- int len, delta;
- char typ, dump;
+ char typ;
gt_waypt_classes_e wpt_class;
Waypoint* wpt;
route_head* trk, *rte;
- len = FREAD_i32;
+ int len = FREAD_i32;
if (FREAD(&typ, 1) < 1) {
fatal(MYNAME ": Attempt to read past EOF.");
}
gbfcopyfrom(ftmp, fin, len);
gbfrewind(ftmp);
- fsave = fin; /* swap standard 'fin' with cached input */
+ gbfile* fsave = fin; /* swap standard 'fin' with cached input */
fin = ftmp;
- dump = 1;
+ char dump = 1;
wpt_class = GDB_DEF_CLASS;
switch (typ) {
case 'W':
wpt = read_waypoint(&wpt_class);
if ((gdb_via == 0) || (wpt_class == 0)) {
- Waypoint* dupe;
waypt_add(wpt);
- dupe = new Waypoint(*wpt);
+ Waypoint* dupe = new Waypoint(*wpt);
ENQUEUE_TAIL(&wayptq_in, &dupe->Q);
} else {
ENQUEUE_TAIL(&wayptq_in_hidden, &wpt->Q);
}
fin = fsave;
- delta = len - gbftell(ftmp);
+ int delta = len - gbftell(ftmp);
is_fatal(delta > 1000000, "Internal consistency error. Delta too big");
// Avoid finite loop on bogus beta files from '06.
const int icon, const int display)
{
char zbuf[32], ffbuf[32];
- int wpt_class;
waypt_ct++; /* increase informational number of written waypoints */
memset(zbuf, 0, sizeof(zbuf));
memset(ffbuf, 0xFF, sizeof(ffbuf));
- wpt_class = wpt->wpt_flags.fmt_use; /* trick */
+ int wpt_class = wpt->wpt_flags.fmt_use; /* trick */
FWRITE_CSTR(shortname); /* uniqe (!!!) shortname */
FWRITE_i32(wpt_class); /* waypoint class */
/* VERSION DEPENDENT CODE */
if (gdb_ver <= GDB_VER_2) {
- QString descr;
-
FWRITE(zbuf, 3);
FWRITE(zbuf, 4);
QString ld;
UrlLink l = wpt->GetUrlLink();
ld = l.url_;
}
- descr = (wpt_class < gt_waypt_class_map_point) ?
- ld : wpt->description;
+ QString descr = (wpt_class < gt_waypt_class_map_point) ?
+ ld : wpt->description;
if ((descr != nullptr) && (wpt_class >= gt_waypt_class_map_point) && \
descr == CSTRc(wpt->shortname)) {
descr.clear();
write_route(const route_head* rte, const QString& rte_name)
{
bounds bounds;
- int points, index;
queue* elem, *tmp;
char zbuf[32], ffbuf[32];
route_compute_bounds(rte, &bounds);
route_write_bounds(&bounds);
- points = ELEMENTS(rte);
+ int points = ELEMENTS(rte);
FWRITE_i32(points);
- index = 0;
+ int index = 0;
QUEUE_FOR_EACH((queue*)&rte->waypoint_list, elem, tmp) {
Waypoint* wpt = (Waypoint*)elem;
Waypoint* next = (Waypoint*)tmp;
- Waypoint* test;
-// garmin_fs_t* gmsd = nullptr;
- int wpt_class;
index++;
rtept_ct++; /* increase informational number of written route points */
gdb_check_waypt(next);
}
- test = gdb_find_wayptq(&wayptq_out, wpt, 1);
+ Waypoint* test = gdb_find_wayptq(&wayptq_out, wpt, 1);
if (test != nullptr) {
wpt = test;
} else {
/* extra_data may contain a modified shortname */
FWRITE_CSTR((wpt->extra_data) ? (char*)wpt->extra_data : wpt->shortname);
- wpt_class = wpt->wpt_flags.fmt_use; /* trick */
+ int wpt_class = wpt->wpt_flags.fmt_use; /* trick */
FWRITE_i32(wpt_class); /* waypoint class */
FWRITE_CSTR(GMSD_GET(cc, "")); /* country */
FWRITE_i32(points); /* total number of waypoints in waypoint list */
QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) {
- double d;
Waypoint* wpt = (Waypoint*)elem;
trkpt_ct++; /* increase informational number of written route points */
FWRITE_LATLON(wpt->longitude);
FWRITE_DBL(wpt->altitude, unknown_alt);
FWRITE_TIME(wpt->GetCreationTime().toTime_t());
- d = WAYPT_GET(wpt, depth, unknown_alt);
+ double d = WAYPT_GET(wpt, depth, unknown_alt);
FWRITE_DBL(d, unknown_alt);
d = WAYPT_GET(wpt, temperature, -99999);
FWRITE_DBL(d, -99999);
}
if (test == nullptr) {
- int icon, display, wpt_class;
+ int display;
Waypoint* wpt = new Waypoint(*refpt);
gdb_check_waypt(wpt);
/* prepare the waypoint */
garmin_fs_t* gmsd = GMSD_FIND(wpt);
- wpt_class = GMSD_GET(wpt_class, -1);
+ int wpt_class = GMSD_GET(wpt_class, -1);
if (wpt_class == -1) {
wpt_class = (route_flag) ? GDB_DEF_HIDDEN_CLASS : GDB_DEF_CLASS;
}
wpt->wpt_flags.fmt_use = wpt_class; /* trick, we need this for the route(s) */
- icon = GMSD_GET(icon, -1);
+ int icon = GMSD_GET(icon, -1);
if (icon < 0) {
if (wpt->icon_descr.isNull()) {
icon = GDB_DEF_ICON;
static void
write_route_cb(const route_head* rte)
{
- gbfile* fsave;
-
if (ELEMENTS(rte) <= 0) {
return;
}
rte_ct++; /* increase informational number of written routes */
- fsave = fout;
+ gbfile* fsave = fout;
fout = ftmp;
write_route(rte, name);
finalize_item(fsave, 'R');
static void
write_track_cb(const route_head* trk)
{
- gbfile* fsave;
-
if (ELEMENTS(trk) <= 0) {
return;
}
trk_ct++; /* increase informational number of written tracks */
- fsave = fout;
+ gbfile* fsave = fout;
fout = ftmp;
write_track(trk, name);
object[FEATURES] = *feature_collection;
QJsonDocument save(object);
- QJsonDocument::JsonFormat style;
- style = compact_opt ? QJsonDocument::Compact : QJsonDocument::Indented;
+ QJsonDocument::JsonFormat style = compact_opt ? QJsonDocument::Compact : QJsonDocument::Indented;
gbfputs(save.toJson(style),ofd);
gbfclose(ofd);
route_head* ggv_bin_track;
Waypoint* wpt;
double lon, lat;
- quint16 header_len;
- quint16 entry_type;
- quint16 entry_subtype;
quint16 line_points;
- quint64 entry_pos;
// header length is usually either 0x90 or 0x00
- header_len = ggv_bin_read16(stream, "map name len");
+ quint16 header_len = ggv_bin_read16(stream, "map name len");
if (header_len > 0) {
ggv_bin_read_bytes(stream, buf, header_len, "map name");
buf.remove(0,4);
if (global_opts.debug_level > 1)
qDebug("------------------------------------ 0x%llx", stream.device()->pos());
- entry_pos = stream.device()->pos();
- entry_type = ggv_bin_read16(stream, "entry type");
+ quint64 entry_pos = stream.device()->pos();
+ quint16 entry_type = ggv_bin_read16(stream, "entry type");
ggv_bin_read16(stream, "entry group");
ggv_bin_read16(stream, "entry zoom");
- entry_subtype = ggv_bin_read16(stream, "entry subtype");
+ quint16 entry_subtype = ggv_bin_read16(stream, "entry subtype");
if (entry_subtype != 1) {
ggv_bin_read_text32(stream, buf, "text len");
ggv_bin_read_v34_header(QDataStream& stream, quint32& number_labels, quint32 &number_records)
{
QByteArray buf;
- quint16 header_len;
-
+
ggv_bin_read_bytes(stream, buf, 8, "unknown");
number_labels = ggv_bin_read32(stream, "num labels");
number_records = ggv_bin_read32(stream, "num records");
ggv_bin_read16(stream, "unknown");
// 8 bytes ending with 1E 00, contains len of header block
ggv_bin_read16(stream, "unknown");
- header_len = ggv_bin_read16(stream, "header len");
+ quint16 header_len = ggv_bin_read16(stream, "header len");
ggv_bin_read16(stream, "unknown");
ggv_bin_read16(stream, "unknown");
if (header_len > 0) {
ggv_bin_read_v34_common(QDataStream& stream)
{
QByteArray buf;
- QString res;
- quint16 type1;
- quint16 type2;
-
+
ggv_bin_read16(stream, "entry group");
ggv_bin_read16(stream, "entry prop2");
ggv_bin_read16(stream, "entry prop3");
ggv_bin_read16(stream, "entry zoom");
ggv_bin_read16(stream, "entry prop10");
ggv_bin_read_text16(stream, buf, "entry txt");
- res = QString::fromLatin1(buf.constData()).simplified();
- type1 = ggv_bin_read16(stream, "entry type1");
+ QString res = QString::fromLatin1(buf.constData()).simplified();
+ quint16 type1 = ggv_bin_read16(stream, "entry type1");
if (type1 != 1) {
ggv_bin_read_text32(stream, buf, "entry object");
}
- type2 = ggv_bin_read16(stream, "entry type2");
+ quint16 type2 = ggv_bin_read16(stream, "entry type2");
if (type2 != 1) {
ggv_bin_read_text32(stream, buf, "entry object");
}
ggv_bin_read_v34_record(QDataStream& stream)
{
QByteArray buf;
- QString label;
Waypoint *wpt;
route_head* ggv_bin_track;
- quint16 entry_type;
quint32 bmp_len;
quint16 line_points;
double lon, lat;
if (global_opts.debug_level > 1)
qDebug("------------------------------------ 0x%llx", stream.device()->pos());
- entry_type = ggv_bin_read16(stream, "entry type");
- label = ggv_bin_read_v34_common(stream);
+ quint16 entry_type = ggv_bin_read16(stream, "entry type");
+ QString label = ggv_bin_read_v34_common(stream);
switch (entry_type) {
case 0x02:
fin = gbfopen(fname, "rb", MYNAME);
for (;;) {
- int cin;
-
- cin = gbfgetc(fin);
+ int cin = gbfgetc(fin);
if (cin < 0) {
break;
}
if (cin == '\0') {
double ver = 0;
- char* sver;
if (strncmp(magic, "DOMGVGPS Logfile V", 18) != 0) {
break;
}
- sver = &magic[18];
+ char* sver = &magic[18];
sscanf(sver, "%lf:", &ver);
ggv_log_ver = ver * 10;
if ((ggv_log_ver == 10) || (ggv_log_ver == 25)) {
static void
ggv_log_read()
{
- signed char* buf;
int bufsz = 0, len;
route_head* trk = nullptr;
break;
}
- buf = (signed char*) xmalloc(bufsz);
+ signed char* buf = (signed char*) xmalloc(bufsz);
while ((len = gbfread(buf, 1, bufsz, fin))) {
- int deg, min;
- double xlat, xlon;
- float sec;
struct tm tm;
- Waypoint* wpt;
if (len != bufsz) {
break;
memset(&tm, 0, sizeof(tm));
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
- deg = (int16_t) le_read16(&buf[0]);
- min = le_read16(&buf[2]);
- sec = le_read_float(&buf[4]);
- xlat = (double)deg + ((double)min / 60.0) + (sec / 3600.0);
+ int deg = (int16_t) le_read16(&buf[0]);
+ int min = le_read16(&buf[2]);
+ float sec = le_read_float(&buf[4]);
+ double xlat = (double)deg + ((double)min / 60.0) + (sec / 3600.0);
wpt->latitude = xlat;
deg = (int16_t) le_read16(&buf[8]);
min = le_read16(&buf[10]);
sec = le_read_float(&buf[12]);
- xlon = (double)deg + ((double)min / 60.0) + (sec / 3600.0);
+ double xlon = (double)deg + ((double)min / 60.0) + (sec / 3600.0);
wpt->longitude = xlon;
WAYPT_SET(wpt, course, le_read16(&buf[16 + 0]));
int milliseconds = 0;
if (ggv_log_ver == 10) {
- double secs;
-
wpt->altitude = le_read16(&buf[16 + 2]);
WAYPT_SET(wpt, speed, le_read16(&buf[16 + 4]));
tm.tm_year = le_read16(&buf[16 + 8]);
tm.tm_mday = le_read16(&buf[16 + 12]);
tm.tm_hour = le_read16(&buf[16 + 14]);
tm.tm_min = le_read16(&buf[16 + 16]);
- secs = le_read_double(&buf[16 + 18]);
+ double secs = le_read_double(&buf[16 + 18]);
tm.tm_sec = (int)secs;
milliseconds = lround((secs - tm.tm_sec) * 1000.0);
} else {
Waypoint* prev = nullptr;
QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) {
- double latmin, lonmin, latsec, lonsec;
- int latint, lonint;
double course = 0, speed = 0;
struct tm tm;
Waypoint* wpt = (Waypoint*)elem;
double secs = 0;
- latint = wpt->latitude;
- lonint = wpt->longitude;
- latmin = 60.0 * (fabs(wpt->latitude) - latint);
- lonmin = 60.0 * (fabs(wpt->longitude) - lonint);
- latsec = 60.0 * (latmin - floor(latmin));
- lonsec = 60.0 * (lonmin - floor(lonmin));
+ int latint = wpt->latitude;
+ int lonint = wpt->longitude;
+ double latmin = 60.0 * (fabs(wpt->latitude) - latint);
+ double lonmin = 60.0 * (fabs(wpt->longitude) - lonint);
+ double latsec = 60.0 * (latmin - floor(latmin));
+ double lonsec = 60.0 * (lonmin - floor(lonmin));
if (wpt->creation_time.isValid()) {
time_t t = wpt->GetCreationTime().toTime_t();
static void
ggv_ovl_read()
{
- int symbols;
-
- symbols = inifile_readint_def(inifile, "Overlay", "Symbols", -1);
+ int symbols = inifile_readint_def(inifile, "Overlay", "Symbols", -1);
for (int i = 1; i <= symbols; i++) {
- int points;
- OVL_SYMBOL_TYP type;
char symbol[32];
snprintf(symbol, sizeof(symbol), "Symbol %d", i);
- type = (OVL_SYMBOL_TYP) inifile_readint_def(inifile, symbol, "Typ", 0);
- points = inifile_readint_def(inifile, symbol, "Punkte", -1);
+ OVL_SYMBOL_TYP type = (OVL_SYMBOL_TYP) inifile_readint_def(inifile, symbol, "Typ", 0);
+ int points = inifile_readint_def(inifile, symbol, "Punkte", -1);
switch (type) {
}
if (points > 0) {
- route_head* rte, *trk;
+ route_head* trk;
- rte = trk = route_head_alloc();
+ route_head* rte = trk = route_head_alloc();
if (group > 1) {
route_add_head(rte);
route_ct++;
static void
track_disp_cb(const route_head* trk)
{
- int i;
queue* elem, *tmp;
int waypt_ct = trk->rte_waypt_ct;
gbfprintf(fout, "Size=105\n");
gbfprintf(fout, "Punkte=%d\n", waypt_ct);
- i = 0;
+ int i = 0;
QUEUE_FOR_EACH(&(trk->waypoint_list), elem, tmp) {
static void
route_disp_cb(const route_head* rte)
{
- int i;
queue* elem, *tmp;
- Waypoint* prev;
int waypt_ct = rte->rte_waypt_ct;
if (waypt_ct <= 0) {
color = OVL_COLOR_RED;
- i = 0;
- prev = nullptr;
+ int i = 0;
+ Waypoint* prev = nullptr;
QUEUE_FOR_EACH(&(rte->waypoint_list), elem, tmp) {
static int
get_direction(const Waypoint* A, const Waypoint* B)
{
- double lata, lona, latb, lonb;
- double dist, dir;
- int res;
-
- lata = RAD(A->latitude);
- lona = RAD(A->longitude);
- latb = RAD(B->latitude);
- lonb = RAD(B->longitude);
+ double lata = RAD(A->latitude);
+ double lona = RAD(A->longitude);
+ double latb = RAD(B->latitude);
+ double lonb = RAD(B->longitude);
- dist = gcdist(lata, lona, latb, lonb);
- dir = acos((sin(latb) - sin(lata) * cos(dist)) / (cos(lata) * sin(dist)));
+ double dist = gcdist(lata, lona, latb, lonb);
+ double dir = acos((sin(latb) - sin(lata) * cos(dist)) / (cos(lata) * sin(dist)));
if (lonb < lona) {
dir = -dir;
}
- res = (int) DEG(dir);
+ int res = (int) DEG(dir);
res = 360 - (res + 270);
if (res < 0) {
res += 360;
static int
serial_recv_byte()
{
- int result;
/* allow for a delay of 4s */
- result = gbser_readc_wait(serial_handle, 4000);
+ int result = gbser_readc_wait(serial_handle, 4000);
switch (result) {
case gbser_ERROR:
fatal("serial_recv_byte(): error reading one byte\n");
static void
serial_write_byte(uint8_t byte)
{
- int n;
if (global_opts.debug_level > 1) {
printf("0x%02x (%d), ", byte, byte);
}
- n = gbser_writec(serial_handle, byte);
+ int n = gbser_writec(serial_handle, byte);
if (n == gbser_ERROR) {
fatal("globalsat_probe_device(): write failed\n");
}
if (!opt_input_dump_file) {
result=serial_recv_byte();
} else {
- int bytes;
- bytes=gbfread(&result, 1, 1, in_file);
+ int bytes = gbfread(&result, 1, 1, in_file);
is_fatal((bytes != 1), MYNAME ": read error");
}
// Check if byte sould be dumped also into a file
static uint8_t*
globalsat_read_package(int* out_length, uint8_t* out_DeviceCommand)
{
- uint8_t DeviceCommand, len_h, len_l, crc;
- uint8_t* payload;
- int length;
+ uint8_t crc;
uint8_t calc_crc = 0;
- DeviceCommand = recv_byte();
+ uint8_t DeviceCommand = recv_byte();
if (global_opts.debug_level > 1) {
printf("DeviceCommand: 0x%02x ", DeviceCommand);
}
- len_h = recv_byte();
+ uint8_t len_h = recv_byte();
calc_crc ^= len_h;
- len_l = recv_byte();
+ uint8_t len_l = recv_byte();
calc_crc ^= len_l;
- length = (len_h << 8) + len_l;
+ int length = (len_h << 8) + len_l;
if (global_opts.debug_level > 1) {
printf("len=%d Payload:", length);
}
- payload = (uint8_t*) malloc(length);
+ uint8_t* payload = (uint8_t*) malloc(length);
if (payload == nullptr) {
goto error_out;
}
globalsat_send_simple(CommandWhoAmI);
- uint8_t* payload;
int len;
uint8_t DeviceCommand;
- payload = globalsat_read_package(&len, &DeviceCommand);
+ uint8_t* payload = globalsat_read_package(&len, &DeviceCommand);
if ((len > 0) && (payload != nullptr)) {
if (global_opts.debug_level > 1) {
printf("Got package!!!\n");
//CommandGetTrackFileHeaders
globalsat_send_simple(CommandGetWaypoints);
- uint8_t* in_payload;
int len;
uint8_t DeviceCommand;
- in_payload = globalsat_read_package(&len, &DeviceCommand);
+ uint8_t* in_payload = globalsat_read_package(&len, &DeviceCommand);
if ((len > 0) && (in_payload != nullptr)) {
if (global_opts.debug_level > 1) {
printf("Got package!!!\n");
printf("Sent...\n");
}
- uint8_t* payload;
int length;
uint8_t DeviceCommand;
- payload = globalsat_read_package(&length, &DeviceCommand);
+ uint8_t* payload = globalsat_read_package(&length, &DeviceCommand);
if ((length > 0) && (payload != nullptr)) {
if (global_opts.debug_level > 1) {
printf("Got package!!! headers\n");
}
- int number_headers;
//payload is packed with a number of trainingheaders with the size of 29bytes each
- number_headers = length / 29; //29=packed sizeof(gh_trainheader)
+ int number_headers = length / 29; //29=packed sizeof(gh_trainheader)
if (global_opts.debug_level > 1) {
printf("length=%d sizeof(gh_trainheader)=%d number_headers=%d\n", length, 29, number_headers);
}
while (! gbfeof(fin)) {
gnav_trl_t rec;
- Waypoint* wpt;
if (gbfread(&rec, sizeof(rec), 1, fin) != 1) {
fatal(MYNAME ": Unexpected EOF (end of file)!\n");
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->SetCreationTime(le_read32(&rec.time));
wpt->latitude = le_read_float(&rec.lat);
static void
gopal_rd_init(const QString& fname)
{
- char* ck;
CHECK_BOOL(optclean);
if (optminspeed) {
minspeed=atof(optminspeed);
if (optdate) {
memset(&opt_tm, 0, sizeof(opt_tm));
- ck = strptime(optdate, "%Y%m%d", &opt_tm);
+ char* ck = strptime(optdate, "%Y%m%d", &opt_tm);
if ((ck == nullptr) || (*ck != '\0') || (strlen(optdate) != 8)) {
fatal(MYNAME ": Invalid date \"%s\"!\n", optdate);
} else if (opt_tm.tm_year < 70) {
{
char* buff;
- char* str, *c;
- int column;
- long line;
- double hmsd,speed;
- int fix, hms;
- route_head* route;
- Waypoint* wpt, *lastwpt=nullptr;
- double lat_old;
+ double hmsd;
+ int fix;
+ int hms;
+ Waypoint* lastwpt=nullptr;
char tbuffer[64];
struct tm tm2;
- lat_old=0;
+ double lat_old = 0;
- route = route_head_alloc();
+ route_head* route = route_head_alloc();
QDateTime qtx;
qtx.setTimeSpec(Qt::UTC);
qtx.setTime_t(tx);
route->rte_name += qtx.toString(Qt::ISODate);
route_add_head(route);
- line=0;
+ long line = 0;
while ((buff = gbfgetstr(fin))) {
- int nfields;
if ((line == 0) && fin->unicode) {
cet_convert_init(CET_CHARSET_UTF8, 1);
}
- str = buff = lrtrim(buff);
+ char* str = buff = lrtrim(buff);
if (*buff == '\0') {
continue;
}
- nfields = gopal_check_line(buff);
+ int nfields = gopal_check_line(buff);
if ((nfields != 8) && (nfields != 11)) {
continue;
}
if ((nfields == 8) && (tx == 0)) {
// fatal(MYNAME ": Invalid date in filename \"%s\", try to set manually using \"date\" switch!\n", buff);
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
- column = -1;
+ int column = -1;
// the format of gopal is quite simple. Unfortunately the developers forgot the date as the first element...
//TICK; TIME; LONG; LAT; HEIGHT; SPEED; Fix; HDOP; SAT
//3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3
- c = csv_lineparse(str, ",", "", column++);
+ char* c = csv_lineparse(str, ",", "", column++);
int millisecs = 0;
while (c != nullptr) {
switch (column) {
lastwpt=wpt;
}
//calculate the speed to reach this waypoint from the last. This way I try to sort out invalid waypoints
- speed=0;
+ double speed = 0;
if (lastwpt !=nullptr) {
speed=3.6*radtometers(gcdist(RAD(lastwpt->latitude), RAD(lastwpt->longitude), RAD(wpt->latitude), RAD(wpt->longitude))) /
abs((int)(wpt->creation_time.toTime_t() - lastwpt->GetCreationTime().toTime_t()));
gopal_write_waypt(const Waypoint* wpt)
{
char tbuffer[64];
- unsigned long timestamp;
int fix=fix_unknown;
//TICK; TIME; LONG; LAT; HEIGHT; SPEED; UN; HDOP; SAT
//3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3
}
}
//MSVC handles time_t as int64, gcc and mac only int32, so convert it:
- timestamp=(unsigned long)wpt->GetCreationTime().toTime_t();
+ unsigned long timestamp = (unsigned long)wpt->GetCreationTime().toTime_t();
gbfprintf(fout, "%lu, %s, %lf, %lf, %5.1lf, %8.5lf, %d, %lf, %d\n",timestamp,tbuffer, wpt->longitude, wpt->latitude,wpt->altitude,
wpt->speed,fix,wpt->hdop,wpt->sat);
}
gpssim_write_pt(const Waypoint* wpt)
{
char obuf[1024];
- double lat, lon;
if WAYPT_HAS(wpt, speed) {
gpssim_write_spd(MPS_TO_KNOTS(wpt->speed));
}
- lat = degrees2ddmm(wpt->latitude);
- lon = degrees2ddmm(wpt->longitude);
+ double lat = degrees2ddmm(wpt->latitude);
+ double lon = degrees2ddmm(wpt->longitude);
snprintf(obuf, sizeof(obuf), "FRWPT,%10.5f,%c,%011.5f,%c,%.1f",
fabs(lat), lat < 0 ? 'S' : 'N',
if (wpt->creation_time.isValid()) {
char tbuf[20];
- int hms, ymd;
- struct tm* tm;
const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = gmtime(&tt);
- hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec;
- ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year;
+ struct tm* tm = gmtime(&tt);
+ int hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec;
+ int ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year;
snprintf(tbuf, sizeof(tbuf), ",%d,%d",ymd, hms);
strcat(obuf, tbuf);
char desc[31];
double lat,lon;
char latdir, londir;
- int ilat, ilon;
long alt;
char alttype;
char icon[3];
- Waypoint* wpt_tmp;
int line = 0;
/*
* Make sure that all waypoints in single read have same
icon[0] = 0;
while ((ibuf = gbfgetstr(file_in))) {
- int n, len;
char* sn;
if ((line++ == 0) && file_in->unicode) {
/* A sharp in column zero or an blank line is a comment */
ibuf = lrtrim(ibuf);
- len = strlen(ibuf);
+ int len = strlen(ibuf);
if ((len == 0) || (*ibuf == '#')) {
continue;
}
ibuf += 9;
}
- n = sscanf(ibuf, "%lf%c %lf%c %ld%c %30[^,] %2s",
- &lat, &latdir, &lon, &londir,
- &alt, &alttype, desc, icon);
+ int n = sscanf(ibuf, "%lf%c %lf%c %ld%c %30[^,] %2s",
+ &lat, &latdir, &lon, &londir,
+ &alt, &alttype, desc, icon);
/* Require at least first threee fields, otherwise ignore */
if (n < 2) {
xfree(sn);
rtrim(sn);
rtrim(desc);
rtrim(icon);
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
wpt_tmp->altitude = alt;
wpt_tmp->shortname = sn;
xfree(sn);
lat /= 100.0;
lon /= 100.0;
- ilon = (int)(lon);
+ int ilon = (int)(lon);
wpt_tmp->longitude = ilon + (lon - ilon)*(100.0/60.0);
- ilat = (int)(lat);
+ int ilat = (int)(lat);
wpt_tmp->latitude = ilat + (lat - ilat) * (100.0/60.0);
wpt_tmp->icon_descr = mag_find_descr_from_token(icon);
waypt_add(wpt_tmp);
static void
gpsutil_disp(const Waypoint* wpt)
{
- double lon,lat;
- QString icon_token;
char* tdesc = xstrdup(wpt->description);
- icon_token = mag_find_token_from_descr(wpt->icon_descr);
+ QString icon_token = mag_find_token_from_descr(wpt->icon_descr);
- lon = degrees2ddmm(wpt->longitude);
- lat = degrees2ddmm(wpt->latitude);
+ double lon = degrees2ddmm(wpt->longitude);
+ double lat = degrees2ddmm(wpt->latitude);
gbfprintf(file_out, "%-8.8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n",
global_opts.synthesize_shortnames ?
gpx_write_gdata(gpx_global_entry* ge, const char* tag)
{
queue* elem, *tmp;
- gpx_global_entry* gep;
if (!gpx_global || QUEUE_EMPTY(&ge->queue)) {
return;
}
writer->writeStartElement(tag);
QUEUE_FOR_EACH(&ge->queue, elem, tmp) {
- gep = BASE_STRUCT(elem, gpx_global_entry, queue);
+ gpx_global_entry* gep = BASE_STRUCT(elem, gpx_global_entry, queue);
writer->writeCharacters(gep->tagdata);
/* Some tags we just output once. */
if ((0 == strcmp(tag, "url")) ||
static void
start_something_else(const QString& el, const QXmlStreamAttributes& attr)
{
- char** avcp;
- int attr_count;
- xml_tag* new_tag;
- fs_xml* fs_gpx;
-
if (!fs_ptr) {
return;
}
- new_tag = new xml_tag;
+ xml_tag* new_tag = new xml_tag;
new_tag->tagname = el;
- attr_count = attr.size();
+ int attr_count = attr.size();
const QXmlStreamNamespaceDeclarations nsdecl = reader->namespaceDeclarations();
const int ns_count = nsdecl.size();
new_tag->attributes = (char**)xcalloc(sizeof(char*),2*(attr_count+ns_count)+1);
- avcp = new_tag->attributes;
+ char** avcp = new_tag->attributes;
for (int i = 0; i < attr_count; i++) {
*avcp = xstrdup(attr[i].qualifiedName().toString());
avcp++;
new_tag->parent = cur_tag;
}
} else {
- fs_gpx = (fs_xml*)fs_chain_find(*fs_ptr, FS_GPX);
+ fs_xml* fs_gpx = (fs_xml*)fs_chain_find(*fs_ptr, FS_GPX);
if (fs_gpx && fs_gpx->tag) {
cur_tag = fs_gpx->tag;
gpx_start(const QString& el, const QXmlStreamAttributes& attr)
{
int passthrough;
- int tag;
/*
* Reset end-of-string without actually emptying/reallocing cdatastr.
*/
cdatastr = QString();
- tag = get_tag(current_tag, &passthrough);
+ int tag = get_tag(current_tag, &passthrough);
switch (tag) {
case tt_gpx:
tag_gpx(attr);
float x;
int passthrough;
static QDateTime gc_log_date;
- tag_type tag;
// Remove leading, trailing whitespace.
cdatastr = cdatastr.trimmed();
- tag = get_tag(current_tag, &passthrough);
+ tag_type tag = get_tag(current_tag, &passthrough);
switch (tag) {
/*
gpx_cdata(const QString& s)
{
QString* cdata;
- xml_tag* tmp_tag;
cdatastr += s;
if (!cur_tag) {
}
if (cur_tag->child) {
- tmp_tag = cur_tag->child;
+ xml_tag* tmp_tag = cur_tag->child;
while (tmp_tag->sibling) {
tmp_tag = tmp_tag->sibling;
}
static void
write_tag_attributes(xml_tag* tag)
{
- char** pa;
- pa = tag->attributes;
+ char** pa = tag->attributes;
if (pa) {
while (*pa) {
writer->writeAttribute(pa[0], pa[1]);
void free_gpx_extras(xml_tag* tag)
{
- char** ap;
-
while (tag) {
if (tag->child) {
free_gpx_extras(tag->child);
}
if (tag->attributes) {
- ap = tag->attributes;
+ char** ap = tag->attributes;
while (*ap) {
xfree(*ap++);
static void
gpx_waypt_pr(const Waypoint* waypointp)
{
- QString oname;
- fs_xml* fs_gpx;
- garmin_fs_t* gmsd; /* gARmIN sPECIAL dATA */
-
writer->writeStartElement(QStringLiteral("wpt"));
writer->writeAttribute(QStringLiteral("lat"), toString(waypointp->latitude));
writer->writeAttribute(QStringLiteral("lon"), toString(waypointp->longitude));
- oname = global_opts.synthesize_shortnames ?
- mkshort_from_wpt(mkshort_handle, waypointp) :
- waypointp->shortname;
+ QString oname = global_opts.synthesize_shortnames ?
+ mkshort_from_wpt(mkshort_handle, waypointp) :
+ waypointp->shortname;
gpx_write_common_position(waypointp, gpxpt_waypoint);
gpx_write_common_description(waypointp, oname);
gpx_write_common_acc(waypointp);
if (!(opt_humminbirdext || opt_garminext)) {
- fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX);
- gmsd = GMSD_FIND(waypointp);
+ fs_xml* fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX);
+ garmin_fs_t* gmsd = GMSD_FIND(waypointp); /* gARmIN sPECIAL dATA */
if (fs_gpx) {
if (! gmsd) {
fprint_xml_chain(fs_gpx->tag, waypointp);
static void
gpx_track_hdr(const route_head* rte)
{
- fs_xml* fs_gpx;
current_trk_head = rte;
writer->writeStartElement(QStringLiteral("trk"));
if (gpx_wversion_num > 10) {
if (!(opt_humminbirdext || opt_garminext)) {
- fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX);
+ fs_xml* fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX);
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag, nullptr);
}
static void
gpx_track_disp(const Waypoint* waypointp)
{
- fs_xml* fs_gpx;
bool first_in_trk = waypointp->Q.prev == ¤t_trk_head->waypoint_list;
if (waypointp->wpt_flags.new_trkseg) {
gpx_write_common_position(waypointp, gpxpt_track);
- /* GPX doesn't require a name on output, so if we made one up
- * on input, we might as well say nothing.
- */
- QString oname;
- oname = global_opts.synthesize_shortnames ?
- mkshort_from_wpt(mkshort_handle, waypointp) :
- waypointp->shortname;
+ QString oname = global_opts.synthesize_shortnames ?
+ mkshort_from_wpt(mkshort_handle, waypointp) :
+ waypointp->shortname;
gpx_write_common_description(waypointp,
waypointp->wpt_flags.shortname_is_synthetic ?
nullptr : oname);
gpx_write_common_acc(waypointp);
if (!(opt_humminbirdext || opt_garminext)) {
- fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX);
+ fs_xml* fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX);
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag, waypointp);
}
static void
gpx_route_hdr(const route_head* rte)
{
- fs_xml* fs_gpx;
-
writer->writeStartElement(QStringLiteral("rte"));
writer->writeOptionalTextElement(QStringLiteral("name"), rte->rte_name);
writer->writeOptionalTextElement(QStringLiteral("desc"), rte->rte_desc);
if (gpx_wversion_num > 10) {
if (!(opt_humminbirdext || opt_garminext)) {
- fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX);
+ fs_xml* fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX);
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag, nullptr);
}
static void
gpx_route_disp(const Waypoint* waypointp)
{
- QString oname;
- fs_xml* fs_gpx;
writer->writeStartElement(QStringLiteral("rtept"));
writer->writeAttribute(QStringLiteral("lat"), toString(waypointp->latitude));
writer->writeAttribute(QStringLiteral("lon"), toString(waypointp->longitude));
- oname = global_opts.synthesize_shortnames ?
- mkshort_from_wpt(mkshort_handle, waypointp) :
- waypointp->shortname;
+ QString oname = global_opts.synthesize_shortnames ?
+ mkshort_from_wpt(mkshort_handle, waypointp) :
+ waypointp->shortname;
gpx_write_common_position(waypointp, gpxpt_route);
gpx_write_common_description(waypointp, oname);
gpx_write_common_acc(waypointp);
if (!(opt_humminbirdext || opt_garminext)) {
- fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX);
+ fs_xml* fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX);
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag, waypointp);
}
double gcdist(double lat1, double lon1, double lat2, double lon2)
{
- double res;
- double sdlat, sdlon;
-
errno = 0;
- sdlat = sin((lat1 - lat2) / 2.0);
- sdlon = sin((lon1 - lon2) / 2.0);
+ double sdlat = sin((lat1 - lat2) / 2.0);
+ double sdlon = sin((lon1 - lon2) / 2.0);
- res = sqrt(sdlat * sdlat + cos(lat1) * cos(lat2) * sdlon * sdlon);
+ double res = sqrt(sdlat * sdlat + cos(lat1) * cos(lat2) * sdlon * sdlon);
if (res > 1.0) {
res = 1.0;
*/
double heading(double lat1, double lon1, double lat2, double lon2)
{
- double v1, v2;
- v1 = sin(lon1 - lon2) * cos(lat2);
- v2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2);
+ double v1 = sin(lon1 - lon2) * cos(lat2);
+ double v2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2);
/* rounding error protection */
if (fabs(v1) < 1e-15) {
v1 = 0.0;
double dot;
- int newpoints;
-
*prjlat = lat1;
*prjlon = lon1;
*frac = 0;
lat3 = RAD(lat3);
lon3 = RAD(lon3);
- newpoints = 1;
+ int newpoints = 1;
if (lat1 == _lat1 && lat2 == _lat2 && lon1 == _lon1 && lon2 == _lon2) {
newpoints = 0;
} else {
double frac,
double* reslat, double* reslon)
{
- double x1, y1, z1;
- double x2, y2, z2;
- double xa, ya, za, la;
+ double xa, ya, za;
/* result must be in degrees */
*reslat = lat1;
lon2 = RAD(lon2);
/* polar to ECEF rectangular */
- x1 = cos(lon1) * cos(lat1);
- y1 = sin(lat1);
- z1 = sin(lon1) * cos(lat1);
- x2 = cos(lon2) * cos(lat2);
- y2 = sin(lat2);
- z2 = sin(lon2) * cos(lat2);
+ double x1 = cos(lon1) * cos(lat1);
+ double y1 = sin(lat1);
+ double z1 = sin(lon1) * cos(lat1);
+ double x2 = cos(lon2) * cos(lat2);
+ double y2 = sin(lat2);
+ double z2 = sin(lon2) * cos(lat2);
/* 'a' is the axis; the line that passes through the center of the earth
* and is perpendicular to the great circle through point 1 and point 2
* It is computed by taking the cross product of the '1' and '2' vectors.*/
crossproduct(x1, y1, z1, x2, y2, z2, &xa, &ya, &za);
- la = sqrt(xa * xa + ya * ya + za * za);
+ double la = sqrt(xa * xa + ya * ya + za * za);
if (la) {
xa /= la;
static QString
fread_string(gbfile* fd)
{
- char* val;
int len = fread_integer(fd);
if (len == 0) {
return nullptr;
}
- val = (char*) xmalloc(len+1);
+ char* val = (char*) xmalloc(len+1);
gbfread(val, 1, len, fd);
while (len != 0 && val[len-1] == ' ') {
len--;
static void
gtm_rd_init(const QString& fname)
{
- int version;
file_in = gbfopen_le(fname, "rb", MYNAME);
- version = fread_integer(file_in);
+ int version = fread_integer(file_in);
QString name = fread_fixedstring(file_in, 10);
if (version == -29921) {
fatal(MYNAME ": Uncompress the file first\n");
double HeightFilter::bilinear(double x1, double y1, double x2, double y2, double x, double y, double z11, double z12, double z21, double z22)
{
- double delta;
-
if (y1 == y2 && x1 == x2) {
return (z11);
}
return (z22*(y-y1)+z11*(y2-y))/(y2-y1);
}
- delta=(y2-y1)*(x2-x1);
+ double delta = (y2-y1)*(x2-x1);
return (z22*(y-y1)*(x-x1)+z12*(y2-y)*(x-x1)+z21*(y-y1)*(x2-x)+z11*(y2-y)*(x2-x))/delta;
}
double HeightFilter::wgs84_separation(double lat, double lon)
{
#include "heightgrid.h"
- int ilat, ilon;
- int ilat1, ilat2, ilon1, ilon2;
+
/* sanity checks to prevent segfault on bad data */
if ((lat > 90.0) || (lat < -90.0)) {
fatal(MYNAME ": Invalid longitude value (%f)\n", lon);
}
- ilat=(int)floor((90.0+lat)/GEOID_GRID_DEG);
- ilon=(int)floor((180.0+lon)/GEOID_GRID_DEG);
+ int ilat = (int)floor((90.0+lat)/GEOID_GRID_DEG);
+ int ilon = (int)floor((180.0+lon)/GEOID_GRID_DEG);
- ilat1=ilat;
- ilon1=ilon;
- ilat2=(ilat < GEOID_ROW-1)? ilat+1:ilat;
- ilon2=(ilon < GEOID_COL-1)? ilon+1:ilon;
+ int ilat1 = ilat;
+ int ilon1 = ilon;
+ int ilat2 = (ilat < GEOID_ROW-1)? ilat+1:ilat;
+ int ilon2 = (ilon < GEOID_COL-1)? ilon+1:ilon;
return bilinear(
ilon1*GEOID_GRID_DEG-180.0,ilat1*GEOID_GRID_DEG-90.0,
void ht_trk_utc(xg_string args, const QXmlStreamAttributes*)
{
struct tm tm;
- time_t utc;
sscanf(CSTRc(args), "%d-%d-%d %d:%d:%d",
&tm.tm_year, &tm.tm_mon,
tm.tm_year -= 1900;
tm.tm_isdst = 0;
- utc = mkgmtime(&tm);
+ time_t utc = mkgmtime(&tm);
wpt_tmp->SetCreationTime(utc);
}
static void data_read()
{
- char name[9], desc[90];
- unsigned char* HxWpt;
- int iDataRead;
- int iWptNum;
- WPT* pWptHxTmp;
+ char name[9];
+ char desc[90];
struct tm tm;
struct tm* ptm;
memset(&tm, 0, sizeof(tm));
- HxWpt = (unsigned char*) xcalloc(GM100_WPO_FILE_SIZE, 1);
+ unsigned char* HxWpt = (unsigned char*) xcalloc(GM100_WPO_FILE_SIZE, 1);
/* read the wpo file to the data-array */
- iDataRead = gbfread(HxWpt, 1, GM100_WPO_FILE_SIZE, file_in);
+ int iDataRead = gbfread(HxWpt, 1, GM100_WPO_FILE_SIZE, file_in);
if (iDataRead == 0) {
fatal(MYNAME ": Error reading data from %s.\n", file_in->name);
}
- iWptNum = le_read16(&((WPTHDR*)HxWpt)->num);
+ int iWptNum = le_read16(&((WPTHDR*)HxWpt)->num);
/* Get the waypoints */
for (int iCount = 0; iCount < iWptNum ; iCount ++) {
Waypoint* wpt_tmp = new Waypoint;
int iWptIndex = le_read16(&((WPTHDR*)HxWpt)->idx[iCount]);
- pWptHxTmp = (WPT*)&HxWpt[OFFS_WPT + (sizeof(WPT) * iWptIndex)];
+ WPT* pWptHxTmp = (WPT*)&HxWpt[OFFS_WPT + (sizeof(WPT) * iWptIndex)];
wpt_tmp->altitude = 0;
strncpy(name,pWptHxTmp->name,sizeof(pWptHxTmp->name));
static void holux_disp(const Waypoint* wpt)
{
- short sIndex;
- WPT* pWptHxTmp;
-
double lon = wpt->longitude * 36000.0;
double lat = wpt->latitude * -36000.0;
lat += (double)((int)lat/abs((int)lat)) * .5;
}
- sIndex = le_read16(&((WPTHDR*)HxWFile)->num);
+ short sIndex = le_read16(&((WPTHDR*)HxWFile)->num);
((WPTHDR*)HxWFile)->idx[sIndex] = sIndex; /* set the waypoint index */
le_write16(&((WPTHDR*)HxWFile)->idx[sIndex], sIndex); /* set the waypoint index */
((WPTHDR*)HxWFile)->used[sIndex] = 0xff; /* Waypoint used */
/* set Waypoint */
- pWptHxTmp = (WPT*)&HxWFile[OFFS_WPT + (sizeof(WPT) * sIndex)];
+ WPT* pWptHxTmp = (WPT*)&HxWFile[OFFS_WPT + (sizeof(WPT) * sIndex)];
memset(pWptHxTmp->name,0x20,sizeof(pWptHxTmp->name));
if (wpt->shortname != nullptr) {
static void data_write()
{
- int iWritten;
short sCount;
/* init the waypoint area*/
waypt_disp_all(holux_disp);
- iWritten = gbfwrite(HxWFile, 1, GM100_WPO_FILE_SIZE,file_out);
+ int iWritten = gbfwrite(HxWFile, 1, GM100_WPO_FILE_SIZE,file_out);
if (iWritten == 0) {
fatal(MYNAME ": Error writing data to %s.\n", file_out->name);
}
static void
html_disp(const Waypoint* wpt)
{
- char* cout;
int32_t utmz;
- double utme, utmn;
+ double utme;
+ double utmn;
char utmzc;
gbfprintf(file_out, "\n<a name=\"%s\"><hr></a>\n", CSTRc(wpt->shortname));
gbfprintf(file_out, "<table width=\"100%%\">\n");
gbfprintf(file_out, "<tr><td><p class=\"gpsbabelwaypoint\">%s - ",(global_opts.synthesize_shortnames) ? CSTRc(mkshort_from_wpt(mkshort_handle, wpt)) : CSTRc(wpt->shortname));
- cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 1);
+ char* cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 1);
gbfprintf(file_out, "%s (%d%c %6.0f %7.0f)", cout, utmz, utmzc, utme, utmn);
xfree(cout);
if (wpt->altitude != unknown_alt) {
humminbird_read_wpt(gbfile* fin)
{
humminbird_waypt_t w;
- double guder;
- int num_icons;
- Waypoint* wpt;
if (! gbfread(&w, 1, sizeof(w), fin)) {
fatal(MYNAME ": Unexpected end of file!\n");
/* All right! Copy the data to the gpsbabel struct... */
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
// Could probably find a way to eliminate the alloc/copy.
char* s = xstrndup(w.name, sizeof(w.name));
wpt->SetCreationTime(w.time);
- guder = gudermannian_i1924(w.north);
+ double guder = gudermannian_i1924(w.north);
wpt->latitude = geocentric_to_geodetic_hwr(guder);
wpt->longitude = (double)w.east / EAST_SCALE * 180.0;
WAYPT_SET(wpt,depth,(double)w.depth / 100.0);
}
- num_icons = sizeof(humminbird_icons) / sizeof(humminbird_icons[0]);
+ int num_icons = sizeof(humminbird_icons) / sizeof(humminbird_icons[0]);
if (w.icon < num_icons) {
wpt->icon_descr = humminbird_icons[w.icon];
}
{
humminbird_trk_header_t th;
- humminbird_trk_point_t* points;
- route_head* trk;
- Waypoint* first_wpt;
- int32_t accum_east;
- int32_t accum_north;
- double g_lat;
if (! gbfread(&th, 1, sizeof(th), fin)) {
fatal(MYNAME ": Unexpected end of file reading header!\n");
/* num_points is actually one too big, because it includes the value in
the header. But we want the extra point at the end because the
freak-value filter below looks at points[i+1] */
- points = (humminbird_trk_point_t*) xcalloc(th.num_points, sizeof(humminbird_trk_point_t));
+ humminbird_trk_point_t* points = (humminbird_trk_point_t*) xcalloc(th.num_points, sizeof(humminbird_trk_point_t));
if (! gbfread(points, sizeof(humminbird_trk_point_t), th.num_points-1, fin)) {
fatal(MYNAME ": Unexpected end of file reading points!\n");
}
- accum_east = th.start_east;
- accum_north = th.start_north;
+ int32_t accum_east = th.start_east;
+ int32_t accum_north = th.start_north;
- trk = route_head_alloc();
+ route_head* trk = route_head_alloc();
track_add_head(trk);
// TODO: find a way to eliminate the copy.
/* We create one wpt for the info in the header */
- first_wpt = new Waypoint;
- g_lat = gudermannian_i1924(accum_north);
+ Waypoint* first_wpt = new Waypoint;
+ double g_lat = gudermannian_i1924(accum_north);
first_wpt->latitude = geocentric_to_geodetic_hwr(g_lat);
first_wpt->longitude = accum_east/EAST_SCALE * 180.0;
first_wpt->altitude = 0.0;
for (int i = 0 ; i<th.num_points-1 ; i++) {
Waypoint* wpt = new Waypoint;
- int16_t next_deltaeast, next_deltanorth;
- double guder;
points[i].depth = be_read16(&points[i].depth);
points[i].deltaeast = be_read16(&points[i].deltaeast);
/* Every once in a while the delta values are
32767 followed by -32768. Filter that. */
- next_deltaeast = be_read16(&points[i+1].deltaeast);
+ int16_t next_deltaeast = be_read16(&points[i+1].deltaeast);
if (points[ i ].deltaeast == 32767 &&
next_deltaeast == -32768) {
points[ i ].deltaeast = -1;
points[i+1].deltaeast = 0; /* BE 0 == LE 0 */
}
- next_deltanorth = be_read16(&points[i+1].deltanorth);
+ int16_t next_deltanorth = be_read16(&points[i+1].deltanorth);
if (points[ i ].deltanorth == 32767 &&
next_deltanorth == -32768) {
points[ i ].deltanorth = -1;
accum_east += points[i].deltaeast;
accum_north += points[i].deltanorth;
- guder = gudermannian_i1924(accum_north);
+ double guder = gudermannian_i1924(accum_north);
wpt->latitude = geocentric_to_geodetic_hwr(guder);
wpt->longitude = accum_east/EAST_SCALE * 180.0;
wpt->altitude = 0.0;
{
humminbird_trk_header_old_t th;
- humminbird_trk_point_old_t* points;
- route_head* trk;
- Waypoint* first_wpt;
- int32_t accum_east;
- int32_t accum_north;
- double g_lat;
const int file_len = 8048;
char namebuf[TRK_NAME_LEN];
/* num_points is actually one too big, because it includes the value in
the header. But we want the extra point at the end because the
freak-value filter below looks at points[i+1] */
- points = (humminbird_trk_point_old_t*)xcalloc(th.num_points, sizeof(humminbird_trk_point_old_t));
+ humminbird_trk_point_old_t* points = (humminbird_trk_point_old_t*)xcalloc(th.num_points, sizeof(humminbird_trk_point_old_t));
if (! gbfread(points, sizeof(humminbird_trk_point_old_t), th.num_points-1, fin)) {
fatal(MYNAME ": Unexpected end of file reading points!\n");
}
- accum_east = th.start_east;
- accum_north = th.start_north;
+ int32_t accum_east = th.start_east;
+ int32_t accum_north = th.start_north;
- trk = route_head_alloc();
+ route_head* trk = route_head_alloc();
track_add_head(trk);
/* The name is not in the header, but at the end of the file.
/* We create one wpt for the info in the header */
- first_wpt = new Waypoint;
- g_lat = gudermannian_i1924(accum_north);
+ Waypoint* first_wpt = new Waypoint;
+ double g_lat = gudermannian_i1924(accum_north);
first_wpt->latitude = geocentric_to_geodetic_hwr(g_lat);
first_wpt->longitude = accum_east/EAST_SCALE * 180.0;
first_wpt->altitude = 0.0;
for (int i = 0 ; i<th.num_points-1 ; i++) {
Waypoint* wpt = new Waypoint;
-// int16_t next_deltaeast, next_deltanorth;
- double guder;
points[i].deltaeast = be_read16(&points[i].deltaeast);
points[i].deltanorth = be_read16(&points[i].deltanorth);
accum_east += points[i].deltaeast;
accum_north += points[i].deltanorth;
- guder = gudermannian_i1924(accum_north);
+ double guder = gudermannian_i1924(accum_north);
wpt->latitude = geocentric_to_geodetic_hwr(guder);
wpt->longitude = accum_east/EAST_SCALE * 180.0;
wpt->altitude = 0.0;
humminbird_read()
{
while (! gbfeof(fin)) {
- uint32_t signature;
-
- signature = gbfgetuint32(fin);
+ uint32_t signature = gbfgetuint32(fin);
switch (signature) {
case WPT_MAGIC:
humminbird_write_waypoint(const Waypoint* wpt)
{
humminbird_waypt_t hum;
- double lat, north, east;
int num_icons = sizeof(humminbird_icons) / sizeof(humminbird_icons[0]);
be_write16(&hum.num, waypoint_num++);
hum.icon = 0; /* i.e. "Diamond" as part of "Diamond, Green" or "Green Diamond" */
for (int i = 0; i < num_icons; i++) {
char* match;
- int j;
xasprintf(&match, "*%s*", humminbird_icons[i]);
- j = wpt->icon_descr.compare(match, Qt::CaseInsensitive);
+ int j = wpt->icon_descr.compare(match, Qt::CaseInsensitive);
xfree(match);
if (j != 0) {
hum.icon = i;
be_write32(&hum.time, wpt->GetCreationTime().toTime_t());
- east = wpt->longitude / 180.0 * EAST_SCALE;
+ double east = wpt->longitude / 180.0 * EAST_SCALE;
be_write32(&hum.east, si_round((east)));
- lat = geodetic_to_geocentric_hwr(wpt->latitude);
- north = inverse_gudermannian_i1924(lat);
+ double lat = geodetic_to_geocentric_hwr(wpt->latitude);
+ double north = inverse_gudermannian_i1924(lat);
be_write32(&hum.north, si_round(north));
- QString name;
- name = (global_opts.synthesize_shortnames)
- ? mkshort_from_wpt(wptname_sh, wpt)
- : mkshort(wptname_sh, wpt->shortname);
+ QString name = (global_opts.synthesize_shortnames)
+ ? mkshort_from_wpt(wptname_sh, wpt)
+ : mkshort(wptname_sh, wpt->shortname);
memset(&hum.name, 0, sizeof(hum.name));
memcpy(&hum.name, CSTR(name), name.length());
trk_head = nullptr;
last_time = 0;
if (trk->rte_waypt_ct > 0) {
- QString name;
trk_head = (humminbird_trk_header_t*) xcalloc(1, sizeof(humminbird_trk_header_t));
trk_points = (humminbird_trk_point_t*) xcalloc(max_points, sizeof(humminbird_trk_point_t));
- name = mkshort(trkname_sh, trk->rte_name);
+ QString name = mkshort(trkname_sh, trk->rte_name);
strncpy(trk_head->name, CSTR(name), sizeof(trk_head->name)-1);
be_write16(&trk_head->trk_num, trk->rte_num);
}
static void
humminbird_track_cb(const Waypoint* wpt)
{
- int32_t north, east;
- double lat;
- int i;
-
if (trk_head == nullptr) {
return;
}
- i = trk_head->num_points;
+ int i = trk_head->num_points;
- east = si_round(wpt->longitude / 180.0 * EAST_SCALE);
- lat = geodetic_to_geocentric_hwr(wpt->latitude);
- north = si_round(inverse_gudermannian_i1924(lat));
+ int32_t east = si_round(wpt->longitude / 180.0 * EAST_SCALE);
+ double lat = geodetic_to_geocentric_hwr(wpt->latitude);
+ int32_t north = si_round(inverse_gudermannian_i1924(lat));
if (wpt->creation_time.isValid()) {
last_time = wpt->GetCreationTime().toTime_t();
static void
humminbird_write_rtept(const Waypoint* wpt)
{
- int i;
-
if (humrte == nullptr) {
return;
}
- i = gb_ptr2int(wpt->extra_data);
+ int i = gb_ptr2int(wpt->extra_data);
if (i <= 0) {
return;
}
*/
static igc_rec_type_t get_record(char** rec)
{
- size_t len;
char* c;
retry:
*rec = c = gbfgetstr(file_in);
return rec_none;
}
- len = strlen(c);
+ size_t len = strlen(c);
/* Trackwiev writes (bogus) blank links between each record */
if (len == 0) {
char task_num[5];
char task_desc[MAXRECLEN];
- Waypoint* wpt;
unsigned int lat_deg, lat_min, lat_frac;
unsigned int lon_deg, lon_min, lon_frac;
char lat_hemi[2], lon_hemi[2];
fatal(MYNAME ": task waypoint (C) record parse error\n%s", rec);
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = ('N' == lat_hemi[0] ? 1 : -1) *
(lat_deg + (lat_min * 1000 + lat_frac) / 1000.0 / 60);
static void data_read()
{
char* ibuf;
- igc_rec_type_t rec_type;
unsigned int hours, mins, secs;
unsigned int lat_deg, lat_min, lat_frac;
unsigned int lon_deg, lon_min, lon_frac;
strcpy(trk_desc, HDRMAGIC HDRDELIM);
while (true) {
- rec_type = get_record(&ibuf);
+ igc_rec_type_t rec_type = get_record(&ibuf);
switch (rec_type) {
case rec_manuf_id:
// Manufacturer/ID record already found in rd_init().
long lon_milliminutes = lround(wpt->longitude * 60000.0);
char lat_hemi = lat_milliminutes < 0 ? 'S' : 'N';
char lon_hemi = lon_milliminutes < 0 ? 'W' : 'E';
- ldiv_t lat_digits;
- ldiv_t lon_digits;
- lat_digits = ldiv(labs(lat_milliminutes), 60000L);
- lon_digits = ldiv(labs(lon_milliminutes), 60000L);
+ ldiv_t lat_digits = ldiv(labs(lat_milliminutes), 60000L);
+ ldiv_t lon_digits = ldiv(labs(lon_milliminutes), 60000L);
if (snprintf(str, 18, "%02ld%05ld%c%03ld%05ld%c",
lat_digits.quot, lat_digits.rem, lat_hemi, lon_digits.quot, lon_digits.rem, lon_hemi) != 17) {
static void wr_task_hdr(const route_head* rte)
{
unsigned char have_takeoff = 0;
- const Waypoint* wpt;
char flight_date[7] = "000000";
char task_desc[MAXRECLEN] = "";
int num_tps = rte->rte_waypt_ct - 2;
}
// See if the takeoff and landing waypoints are there or if we need to
// generate them.
- wpt = (Waypoint*) QUEUE_LAST(&rte->waypoint_list);
+ const Waypoint* wpt = (Waypoint*) QUEUE_LAST(&rte->waypoint_list);
if (wpt->shortname.startsWith("LANDING")) {
num_tps--;
}
*/
static void wr_fix_record(const Waypoint* wpt, int pres_alt, int gnss_alt)
{
- struct tm* tm;
-
const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = gmtime(&tt);
+ struct tm* tm = gmtime(&tt);
if (nullptr == tm) {
fatal(MYNAME ": bad track timestamp\n");
*/
static int correlate_tracks(const route_head* pres_track, const route_head* gnss_track)
{
- const queue* elem;
- double last_alt, alt_diff;
+ double alt_diff;
double speed;
- time_t pres_time, gnss_time;
+ time_t pres_time;
+ time_t gnss_time;
int time_diff;
- const Waypoint* wpt;
// Deduce the landing time from the pressure altitude track based on
// when we last descended to within 10m of the final track altitude.
- elem = QUEUE_LAST(&pres_track->waypoint_list);
- last_alt = ((Waypoint*) elem)->altitude;
+ const queue* elem = QUEUE_LAST(&pres_track->waypoint_list);
+ double last_alt = ((Waypoint*) elem)->altitude;
do {
elem = elem->prev;
if (&pres_track->waypoint_list == elem) {
elem = QUEUE_LAST(&gnss_track->waypoint_list);
last_alt = ((Waypoint*) elem)->altitude;
do {
- wpt = (Waypoint*) elem;
+ const Waypoint* wpt = (Waypoint*) elem;
elem = elem->prev;
if (&gnss_track->waypoint_list == elem) {
// No track left
{
static const queue* prev_elem = nullptr;
static const queue* curr_elem = nullptr;
- const Waypoint* prev_wpt;
- const Waypoint* curr_wpt;
int time_diff;
- double alt_diff;
// Start search at the beginning of the track
if (!prev_elem) {
curr_elem = QUEUE_NEXT(prev_elem);
}
- prev_wpt = (Waypoint*) prev_elem;
- curr_wpt = (Waypoint*) curr_elem;
+ const Waypoint* prev_wpt = (Waypoint*) prev_elem;
+ const Waypoint* curr_wpt = (Waypoint*) curr_elem;
if (QUEUE_FIRST(&track->waypoint_list) == curr_elem) {
if (curr_wpt->GetCreationTime().toTime_t() == time) {
// Avoid divide by zero
return curr_wpt->altitude;
}
- alt_diff = curr_wpt->altitude - prev_wpt->altitude;
+ double alt_diff = curr_wpt->altitude - prev_wpt->altitude;
return prev_wpt->altitude + (alt_diff / time_diff) * (time - prev_wpt->GetCreationTime().toTime_t());
}
// Reader callback
static void igo8_read()
{
- Waypoint* wpt_tmp;
- route_head* track_head;
igo8_point point;
- track_head = route_head_alloc();
+ route_head* track_head = route_head_alloc();
track_add_head(track_head);
while (in_point_count &&
gbfread(&point, sizeof(point), 1, igo8_file_in) > 0) {
in_point_count--;
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
wpt_tmp->latitude = le_read32(&point.lat) / (double)0x800000;
wpt_tmp->longitude = le_read32(&point.lon) / (double)0x800000;
static unsigned int ascii_to_unicode_2(char* dst, const unsigned int dst_max_length, const char* src)
{
- short* unicode;
int len;
- unicode = cet_str_any_to_uni(src, &cet_cs_vec_ansi_x3_4_1968, &len);
+ short* unicode = cet_str_any_to_uni(src, &cet_cs_vec_ansi_x3_4_1968, &len);
len *= 2; /* real size in bytes */
len = print_unicode(dst, dst_max_length, unicode, len);
static gbfile*
open_gpsbabel_inifile()
{
- QString name;
- QString envstr;
gbfile* res = nullptr;
- envstr = ugetenv("GPSBABELINI");
+ QString envstr = ugetenv("GPSBABELINI");
if (!envstr.isNull()) {
if (QFile(envstr).open(QIODevice::ReadOnly)) {
return gbfopen(envstr, "r", "GPSBabel");
warning("WARNING: GPSBabel-inifile, defined in environment, NOT found!\n");
return nullptr;
}
- name = find_gpsbabel_inifile(""); // Check in current directory first.
+ QString name = find_gpsbabel_inifile(""); // Check in current directory first.
if (name.isNull()) {
#ifdef __WIN32__
// Use &&'s early-out behaviour to try successive file locations: first
ENQUEUE_TAIL(&inifile->secs, &sec->Q);
inifile->isecs++;
} else {
- char* cx;
- inifile_entry_t* entry;
-
if (sec == nullptr) {
fatal("%s: missing section header in '%s'.\n", myname,
qPrintable(gbinipathname));
}
- entry = (inifile_entry_t*) xcalloc(1, sizeof(*entry));
+ inifile_entry_t* entry = (inifile_entry_t*) xcalloc(1, sizeof(*entry));
ENQUEUE_TAIL(&sec->entries, &entry->Q);
sec->ientries++;
- cx = strchr(cin, '=');
+ char* cx = strchr(cin, '=');
if (cx != nullptr) {
*cx = '\0';
cin = lrtrim(cin);
inifile_t*
inifile_init(const QString& filename, const char* myname)
{
- inifile_t* result;
gbfile* fin = nullptr;
if (filename.isEmpty()) {
fin = gbfopen(filename, "rb", myname);
}
- result = (inifile_t*) xcalloc(1, sizeof(*result));
+ inifile_t* result = (inifile_t*) xcalloc(1, sizeof(*result));
QUEUE_INIT(&result->secs);
inifile_load_file(fin, result, myname);
int
inifile_readint(const inifile_t* inifile, const char* section, const char* key, int* value)
{
- char* str;
-
- str = inifile_find_value(inifile, section, key);
+ char* str = inifile_find_value(inifile, section, key);
if (str == nullptr) {
return 0;
double lat1 = 0, lon1 = 0;
double altitude1 = unknown_alt;
unsigned int time1 = 0;
- unsigned int timen;
- double distn;
- double curdist;
- double rt1, rn1, rt2, rn2;
double frac;
if (opt_route) {
} else {
if (opt_interval &&
wpt->creation_time.toTime_t() - time1 > interval) {
- for (timen = time1+interval;
+ for (unsigned int timen = time1+interval;
timen < wpt->creation_time.toTime_t();
timen += interval) {
Waypoint* wpt_new = new Waypoint(*wpt);
}
}
} else if (opt_dist) {
- rt1 = RAD(lat1);
- rn1 = RAD(lon1);
- rt2 = RAD(wpt->latitude);
- rn2 = RAD(wpt->longitude);
- curdist = gcdist(rt1, rn1, rt2, rn2);
+ double rt1 = RAD(lat1);
+ double rn1 = RAD(lon1);
+ double rt2 = RAD(wpt->latitude);
+ double rn2 = RAD(wpt->longitude);
+ double curdist = gcdist(rt1, rn1, rt2, rn2);
curdist = radtomiles(curdist);
if (curdist > dist) {
- for (distn = dist;
+ for (double distn = dist;
distn < curdist;
distn += dist) {
Waypoint* wpt_new = new Waypoint(*wpt);
static int
itracku_device_update_data_read(void* buf, int len)
{
- int rc;
-
if (update_data_buffer_write - update_data_buffer_read >= len) {
memcpy(buf, update_data_buffer_read, len);
update_data_buffer_read += len;
update_data_buffer_read = update_data_buffer;
}
- rc = gbser_read_wait(fd, update_data_buffer_write, update_data_buffer_end - update_data_buffer_write, timeout);
+ int rc = gbser_read_wait(fd, update_data_buffer_write, update_data_buffer_end - update_data_buffer_write, timeout);
if (rc == gbser_ERROR) {
return 0;
}
deg_min_to_deg(volatile uint32_t x)
{
double sign;
- uint32_t sep;
- uint32_t d;
- uint32_t m10000;
// determine the sign
if (x > 0x80000000) {
sign = -1.0;
sign = 1.0;
}
- sep = 1000000;
+ uint32_t sep = 1000000;
// extract degrees
- d = (unsigned int) x / (unsigned int) sep;
+ uint32_t d = (unsigned int) x / (unsigned int) sep;
// extract (minutes * 10000)
- m10000 = x - d * sep;
+ uint32_t m10000 = x - d * sep;
// convert minutes and degrees to a double
return sign * ((double)d + ((double)m10000) / 600000.0);
deg_to_deg_min(double x)
{
int32_t sign;
- double d;
- double f;
// determine sign
if (x >= 0) {
}
// integer degrees
- d = floor(x);
+ double d = floor(x);
// fractional part
- f = x - d;
+ double f = x - d;
return
(uint32_t)d * 1000000 + // multiply integer degrees to shift it to the right digits.
static Waypoint*
to_waypoint(itracku_data_record* d)
{
- Waypoint* wp;
- wp = new Waypoint;
+ Waypoint* wp = new Waypoint;
wp->longitude = deg_min_to_deg(le_read32(d->longitude));
wp->latitude = deg_min_to_deg(le_read32(d->latitude));
wp->SetCreationTime(decode_itracku_time(le_read32(d->creation_time)));
init_device()
{
int rc;
- const char* greeting;
// verify that we have a MTK based logger...
dbg(1, "verifying device on port %s", port);
itracku_device_write_string("WP AP-Exit");
gbser_flush(fd);
itracku_device_write_string("W'P Camera Detect");
- greeting = itracku_device_read_string();
+ const char* greeting = itracku_device_read_string();
if (0 == strcmp(greeting , "WP GPS+BT")) {
dbg(1, "device recognised on port %s", port);
itracku_file_read_last_time(gbfile* fin)
{
itracku_data_record d;
- gbsize_t s;
- s = sizeof(itracku_data_record);
+ gbsize_t s = sizeof(itracku_data_record);
gbfseek(fin, 0, SEEK_END);
if (gbftell(fin) < s) {
return 0;
char fix;
unsigned int dmy;
double speed,course;
- Waypoint* waypt;
- double fsec;
struct tm tm;
int rc = sscanf(ibuf,"$GPRMC,%lf,%c,%lf,%c,%lf,%c,%lf,%lf,%u",
return nullptr;
}
- fsec = hms - (int)hms;
+ double fsec = hms - (int)hms;
tm.tm_sec = (long) hms % 100;
hms = hms / 100;
dmy = dmy / 100;
tm.tm_mday = dmy;
- waypt = new Waypoint;
+ Waypoint* waypt = new Waypoint;
WAYPT_SET(waypt, speed, KNOTS_TO_MPS(speed));
itracku_rt_position(posn_status*)
{
char line[1024];
- Waypoint* wpt;
while (true) {
gbser_read_line(fd, line, sizeof(line), 5000, 13, 10);
dbg(1, line);
- wpt = gprmc_parse(line);
+ Waypoint* wpt = gprmc_parse(line);
if (wpt) {
return wpt;
}
static time_t
jtr_parse_time(const char* str, struct tm* tm, int* milli)
{
- long int hms;
char* dot;
- hms = strtol(str, &dot, 10);
+ long int hms = strtol(str, &dot, 10);
if (hms > 0) {
tm->tm_sec = hms % 100;
hms = hms / 100;
route_head* trk = nullptr;
while ((str = gbfgetstr(fin))) {
- Waypoint* wpt;
struct tm tm;
- char* tmp;
char valid = 'V';
- double lat, lon;
- float speed, course, mcourse, mvar, mdev;
+ double lon;
+ float course, mcourse, mvar, mdev;
time_t time = 0;
int mills = 0;
char buf[32];
- char mvardir, mdevdir;
+ char mdevdir;
line++;
}
memset(&tm, 0, sizeof(tm));
- lat = lon = 999;
- speed = course = mcourse = mvar = mdev = -1;
- mvardir = mdevdir = 0;
+ double lat = lon = 999;
+ float speed = course = mcourse = mvar = mdev = -1;
+ char mvardir = mdevdir = 0;
int column = -1;
- tmp = str;
+ char* tmp = str;
while ((str = csv_lineparse(tmp, ",", "", column++))) {
tmp = nullptr;
continue;
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = lat;
wpt->longitude = lon;
static void kml_step_color()
{
- int color_seq;
// Map kml_color_sequencer.seq to an integer in the range [0, KML_COLOR_LIMIT*6).
// Note that color_seq may be outside this range if the cast from float to int fails.
- color_seq = ((int) kml_color_sequencer.seq) % (KML_COLOR_LIMIT * 6);
+ int color_seq = ((int) kml_color_sequencer.seq) % (KML_COLOR_LIMIT * 6);
if (global_opts.debug_level >= 1) {
printf(MYNAME ": kml_color_sequencer seq %f %d, step %f\n",kml_color_sequencer.seq, color_seq, kml_color_sequencer.step);
}
void gx_trk_coord(xg_string args, const QXmlStreamAttributes*)
{
- Waypoint* trkpt;
double lat, lon, alt;
- int n;
if (! gx_trk_times || gx_trk_times->isEmpty()) {
fatal(MYNAME ": There were more gx:coord elements than the number of when elements.\n");
}
- trkpt = new Waypoint;
+ Waypoint* trkpt = new Waypoint;
trkpt->SetCreationTime(gx_trk_times->takeFirst());
- n = sscanf(CSTR(args), "%lf %lf %lf", &lon, &lat, &alt);
+ int n = sscanf(CSTR(args), "%lf %lf %lf", &lon, &lat, &alt);
// Empty gx_coord elements are allowed to balance the number of when elements,
// but if we get one we will throw away the time as we don't have a location.
// It is not clear that coord elements without altitude are allowed, but our
void kml_output_trkdescription(const route_head* header, computed_trkdata* td)
{
const char* max_alt_units;
- double max_alt;
const char* min_alt_units;
- double min_alt;
const char* distance_units;
- double distance;
if (!td || !trackdata) {
return;
QString hstring;
gpsbabel::XmlStreamWriter hwriter(&hstring);
- max_alt = fmt_altitude(td->max_alt, &max_alt_units);
- min_alt = fmt_altitude(td->min_alt, &min_alt_units);
- distance = fmt_distance(td->distance_meters, &distance_units);
+ double max_alt = fmt_altitude(td->max_alt, &max_alt_units);
+ double min_alt = fmt_altitude(td->min_alt, &min_alt_units);
+ double distance = fmt_distance(td->distance_meters, &distance_units);
writer->writeEmptyElement(QStringLiteral("snippet"));
kml_td(hwriter, QStringLiteral("Max Cadence"), QStringLiteral(" %1 rpm ").arg(QString::number(td->max_cad)));
}
if (td->start && td->end) {
- gpsbabel::DateTime t;
- t = QDateTime::fromTime_t(td->start);
+ gpsbabel::DateTime t = QDateTime::fromTime_t(td->start);
if (t.isValid()) {
kml_td(hwriter, QStringLiteral("Start Time"), t.toPrettyString());
}
if (td->start && td->end) {
writer->writeStartElement(QStringLiteral("TimeSpan"));
- gpsbabel::DateTime t;
- t = QDateTime::fromTime_t(td->start);
+ gpsbabel::DateTime t = QDateTime::fromTime_t(td->start);
writer->writeTextElement(QStringLiteral("begin"), t.toPrettyString());
t = QDateTime::fromTime_t(td->end);
writer->writeTextElement(QStringLiteral("end"), t.toPrettyString());
static void kml_output_description(const Waypoint* pt)
{
const char* alt_units;
- double alt;
if (!trackdata) {
return;
QString hstring;
gpsbabel::XmlStreamWriter hwriter(&hstring);
- alt = fmt_altitude(pt->altitude, &alt_units);
+ double alt = fmt_altitude(pt->altitude, &alt_units);
writer->writeStartElement(QStringLiteral("description"));
hwriter.writeCharacters(QStringLiteral("\n"));
// to include all our data.
static void kml_write_AbstractView()
{
- double bb_size;
-
// Make a pass through all the points to find the bounds.
if (waypt_count()) {
waypt_disp_all(kml_add_to_bounds);
writer->writeTextElement(QStringLiteral("begin"), kml_time_min.toPrettyString());
}
if (kml_time_max.isValid()) {
- gpsbabel::DateTime time_max;
// In realtime tracking mode, we fudge the end time by a few minutes
// to ensure that the freshest data (our current location) is contained
// within the timespan. Earth's time may not match the GPS because
// the network position. So we shove the end of the timespan out to
// ensure the right edge of that time slider includes us.
//
- time_max = realtime_positioning ? kml_time_max.addSecs(600) : kml_time_max;
+ gpsbabel::DateTime time_max = realtime_positioning ? kml_time_max.addSecs(600) : kml_time_max;
writer->writeTextElement(QStringLiteral("end"), time_max.toPrettyString());
}
writer->writeEndElement(); // Close gx:TimeSpan tag
// It turns out the length of the diagonal of the bounding box gives us a
// reasonable guess for setting the camera altitude.
- bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon,
- kml_bounds.max_lat, kml_bounds.max_lon);
+ double bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon,
+ kml_bounds.max_lat, kml_bounds.max_lon);
// Clamp bottom zoom level. Otherwise, a single point zooms to grass.
if (bb_size < 1000) {
bb_size = 1000;
static void
lmx_print(const Waypoint* wpt)
{
- QString oname;
- QString odesc;
-
/*
* Desparation time, try very hard to get a good shortname
*/
- odesc = wpt->notes;
+ QString odesc = wpt->notes;
if (odesc.isEmpty()) {
odesc = wpt->description;
}
odesc = wpt->shortname;
}
- oname = global_opts.synthesize_shortnames ? odesc : wpt->shortname;
+ QString oname = global_opts.synthesize_shortnames ? odesc : wpt->shortname;
lmx_start_tag(0x47, 2); // landmark
if (!binary) {
static int
lowranceusr_readstr(char* buf, const int maxlen, gbfile* file)
{
- int org, len;
+ int len;
- org = len = gbfgetint32(file);
+ int org = len = gbfgetint32(file);
if (len < 0) {
fatal(MYNAME ": Invalid item length (%d)!\n", len);
} else if (len) {
static int
lowranceusr_find_icon_number_from_desc(const QString& desc)
{
- int n;
-
if (desc.isNull()) {
return DEF_ICON;
}
* If we were given a numeric icon number as a description
* (i.e. 8255), just return that.
*/
- n = desc.toInt();
+ int n = desc.toInt();
if (n) {
return n;
}
lowranceusr_parse_waypt(Waypoint* wpt_tmp)
{
char buff[MAXUSRSTRINGSIZE + 1];
- int text_len;
wpt_tmp->latitude = lat_mm_to_deg(gbfgetint32(file_in));
wpt_tmp->longitude = lon_mm_to_deg(gbfgetint32(file_in));
wpt_tmp->altitude = unknown_alt;
}
- text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
+ int text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
if (text_len) {
buff[text_len] = '\0';
wpt_tmp->shortname = buff;
lowranceusr_parse_routes()
{
char buff[MAXUSRSTRINGSIZE + 1];
- short int num_routes;
- num_routes = gbfgetint16(file_in);
+ short int num_routes = gbfgetint16(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_routes: Num Routes = %d\n", num_routes);
lowranceusr_parse_icons()
{
char buff[MAXUSRSTRINGSIZE + 1];
- short int num_icons;
- num_icons = gbfgetint16(file_in);
+ short int num_icons = gbfgetint16(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_icons: num Icons = %d\n", num_icons);
/* symbol */
(void) gbfread(&buff[0], 4, 1, file_in);
} else {
- Waypoint* wpt_tmp;
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
/* position coord lat & long */
wpt_tmp->latitude = lat_mm_to_deg(gbfgetint32(file_in));
lowranceusr_parse_trails()
{
char buff[MAXUSRSTRINGSIZE + 1];
- short int num_trails, num_section_points;
int trk_num;
/* num trails */
- num_trails = gbfgetint16(file_in);
+ short int num_trails = gbfgetint16(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_trails: num trails = %d\n", num_trails);
while (num_trail_points && !gbfeof(file_in)) {
/* num section points */
- num_section_points = gbfgetint16(file_in);
+ short int num_section_points = gbfgetint16(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_trails: num section points = %d\n", num_section_points);
}
for (int i = 0; i < NumWaypoints && !gbfeof(file_in); i++) {
- Waypoint* wpt_tmp;
-
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
/* Object num */
short object_num = gbfgetint16(file_in);
static void
lowranceusr_waypt_disp(const Waypoint* wpt)
{
- int text_len, Lat, Lon, Time, SymbolId;
- short int WayptType;
+ int Time, SymbolId;
int alt = METERS_TO_FEET(wpt->altitude);
if (wpt->altitude == unknown_alt) {
alt = UNKNOWN_USR_ALTITUDE;
}
- Lat = lat_deg_to_mm(wpt->latitude);
- Lon = lon_deg_to_mm(wpt->longitude);
+ int Lat = lat_deg_to_mm(wpt->latitude);
+ int Lon = lon_deg_to_mm(wpt->longitude);
gbfputint32(Lat, file_out);
gbfputint32(Lon, file_out);
gbfputint32(alt, file_out);
name = wpt->shortname;
}
- text_len = name.length();
+ int text_len = name.length();
if (text_len > MAXUSRSTRINGSIZE) {
text_len = MAXUSRSTRINGSIZE;
}
gbfputint32(SymbolId, file_out);
/* USER waypoint type */
- WayptType = 0;
+ short int WayptType = 0;
gbfputint16(WayptType, file_out);
}
static void
lowranceusr_track_hdr(const route_head* trk)
{
- int text_len;
QString name;
- short num_trail_points, max_trail_size;
char visible=1;
++trail_count;
name = name + QString("Babel %1").arg(trail_count);
}
- text_len = name.length();
+ int text_len = name.length();
if (text_len > MAXUSRSTRINGSIZE) {
text_len = MAXUSRSTRINGSIZE;
}
}
gbfwrite(CSTR(name), 1, text_len, file_out);
- num_trail_points = (short) trk->rte_waypt_ct;
- max_trail_size = MAX_TRAIL_POINTS;
+ short num_trail_points = (short) trk->rte_waypt_ct;
+ short max_trail_size = MAX_TRAIL_POINTS;
if (num_trail_points > max_trail_size) {
num_trail_points = max_trail_size;
}
static void
lowranceusr_route_hdr(const route_head* rte)
{
- int text_len;
char* name, tmp_name[20];
char route_reversed=0;
snprintf(tmp_name, sizeof(tmp_name), "Babel R%u", ++lowrance_route_count);
name = xstrdup(tmp_name);
}
- text_len = strlen(name);
+ int text_len = strlen(name);
if (text_len > MAXUSRSTRINGSIZE) {
text_len = MAXUSRSTRINGSIZE;
}
static void
lowranceusr_merge_track_hdr(const route_head* trk)
{
- int text_len;
char* name, tmp_name[20];
if (++trail_count == 1) {
snprintf(tmp_name, sizeof(tmp_name), "Babel %u", trail_count);
name = xstrdup(tmp_name);
}
- text_len = strlen(name);
+ int text_len = strlen(name);
if (text_len > MAXUSRSTRINGSIZE) {
text_len = MAXUSRSTRINGSIZE;
}
static void
data_write()
{
- short int NumWaypoints, MajorVersion, MinorVersion, NumRoutes, NumTrails;
setshort_length(mkshort_handle, 15);
- MajorVersion = writing_version;
- MinorVersion = 0;
+ short int MajorVersion = writing_version;
+ short int MinorVersion = 0;
- NumWaypoints = waypt_count();
+ short int NumWaypoints = waypt_count();
gbfputint16(MajorVersion, file_out);
gbfputint16(MinorVersion, file_out);
}
/* Route support added 6/21/05 */
- NumRoutes = route_count();
+ short int NumRoutes = route_count();
gbfputint16(NumRoutes, file_out);
if (global_opts.debug_level >= 1) {
}
/* Track support added 6/21/05 */
- NumTrails = track_count();
+ short int NumTrails = track_count();
if (NumTrails && merge) {
NumTrails = 1;
static int
lowranceusr4_readstr(char* buf, const int maxlen, gbfile* file, int bytes_per_char)
{
- int org, len;
+ int len;
int bytesread = 0;
- org = len = gbfgetint32(file); /* bytes */
+ int org = len = gbfgetint32(file); /* bytes */
if (len < 0) {
buf[0] = '\0'; /* seems len=-1 means no string */
return 0;
static time_t
lowranceusr4_get_timestamp(int jd_number, time_t t)
{
- int a, b, c, d, e, m;
- struct tm* ptm, ntm;
- time_t out;
+ struct tm ntm;
/* get UTC time from time_t */
- ptm = gmtime(&t);
+ struct tm* ptm = gmtime(&t);
memset(&ntm, 0, sizeof(ntm));
ntm.tm_hour = ptm->tm_hour;
ntm.tm_min = ptm->tm_min;
ntm.tm_sec = ptm->tm_sec;
/* convert the JD number to get day/month/year */
- a = jd_number + 32044;
- b = (4*a + 3) / 146097;
- c = a - (146097*b) / 4;
- d = (4*c + 3) / 1461;
- e = c - (1461*d) / 4;
- m = (5*e + 2) / 153;
+ int a = jd_number + 32044;
+ int b = (4*a + 3) / 146097;
+ int c = a - (146097*b) / 4;
+ int d = (4*c + 3) / 1461;
+ int e = c - (1461*d) / 4;
+ int m = (5*e + 2) / 153;
ntm.tm_mday = e + 1 - (153*m + 2) / 5;
ntm.tm_mon = m + 3 - 12 * (m / 10) - 1;
ntm.tm_year = 100 * b + d - 4800 + m / 10 - 1900;
/* put it all back together into a unix timestamp in UTC */
- out = mkgmtime(&ntm);
+ time_t out = mkgmtime(&ntm);
return out;
}
static void
lowranceusr4_parse_waypoints()
{
- short int icon_num;
- unsigned int num_waypts, create_date, create_time;
char buff[MAXUSRSTRINGSIZE + 1];
- num_waypts = gbfgetint32(file_in);
+ unsigned int num_waypts = gbfgetint32(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_waypoints: Num waypoints %d\n", num_waypts);
}
for (unsigned int i = 0; i < num_waypts; ++i) {
- Waypoint* wpt_tmp;
-
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
lowranceusr4_fsdata* fsdata = lowranceusr4_alloc_fsdata();
fs_chain_add(&(wpt_tmp->fs), (format_specific_data*) fsdata);
icon description; however it doesn't seem that the icon ids
used in usr4 match those from usr{2,3} so we need a new
mapping. */
- icon_num = gbfgetint16(file_in);
+ short int icon_num = gbfgetint16(file_in);
(void) icon_num; // Hush warning for now.
/* wpt_tmp->icon_descr = lowranceusr_find_desc_from_icon_number(icon_num); */
/* Creation date/time; the date is a Julian day number, and the
time is a unix timestamp. */
- create_date = gbfgetint32(file_in);
- create_time = gbfgetint32(file_in);
+ unsigned int create_date = gbfgetint32(file_in);
+ unsigned int create_time = gbfgetint32(file_in);
// Julian date 2440487 is 1/1/1970. If that's the date we're working
// with, as a practical matter, we have no date, so don't even compute
static void
lowranceusr4_parse_routes()
{
- unsigned int num_routes, text_len;
- unsigned int num_legs;
char buff[MAXUSRSTRINGSIZE + 1];
- Waypoint* wpt_tmp;
- unsigned int uid_unit, uid_seq_low, uid_seq_high;
- num_routes = gbfgetint32(file_in);
+ unsigned int num_routes = gbfgetint32(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_routes: Num routes = %d\n", num_routes);
gbfgetint16(file_in);
/* Route name; input is 2 bytes per char, we convert to 1 */
- text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
+ unsigned int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
if (text_len) {
buff[text_len] = '\0';
rte_head->rte_name = buff;
}
- num_legs = gbfgetint32(file_in);
+ unsigned int num_legs = gbfgetint32(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_routes: route name=%s has %d waypoints\n",
}
for (unsigned int j = 0; j < num_legs; ++j) {
- uid_unit = gbfgetint32(file_in);
- uid_seq_low = gbfgetint32(file_in);
- uid_seq_high = gbfgetint32(file_in);
- wpt_tmp = lowranceusr4_find_waypt(uid_unit, uid_seq_low, uid_seq_high);
+ unsigned int uid_unit = gbfgetint32(file_in);
+ unsigned int uid_seq_low = gbfgetint32(file_in);
+ unsigned int uid_seq_high = gbfgetint32(file_in);
+ Waypoint* wpt_tmp = lowranceusr4_find_waypt(uid_unit, uid_seq_low, uid_seq_high);
if (wpt_tmp) {
if (global_opts.debug_level >= 2) {
printf(MYNAME " parse_routes: added wpt %s to route %s\n",
static void
lowranceusr4_parse_trails()
{
- int num_trails, M, trk_num;
+ int trk_num;
char buff[MAXUSRSTRINGSIZE + 1];
- Waypoint* wpt_tmp;
/* num trails */
- num_trails = gbfgetint32(file_in);
+ int num_trails = gbfgetint32(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_trails: num trails = %d\n", num_trails);
}
for (int j = 0; j < num_trail_pts; ++j) {
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
/* Some unknown bytes */
gbfgetint16(file_in);
wpt_tmp->latitude = gbfgetdbl(file_in) / DEGREESTORADIANS;
/* Mysterious per-trackpoint data, toss it for now */
- M = gbfgetint32(file_in);
+ int M = gbfgetint32(file_in);
for (int k = 0; k < M; ++k) {
gbfgetc(file_in);
gbfgetflt(file_in);
static void
data_read()
{
- short int MajorVersion, MinorVersion;
- int text_len, DataStreamVersion;
- unsigned int create_date, create_time, serial_num;
- unsigned char byte;
char buff[MAXUSRSTRINGSIZE + 1];
- MajorVersion = gbfgetint16(file_in);
+ short int MajorVersion = gbfgetint16(file_in);
reading_version = MajorVersion;
- MinorVersion = gbfgetint16(file_in);
- DataStreamVersion = gbfgetint32(file_in);
+ short int MinorVersion = gbfgetint16(file_in);
+ int DataStreamVersion = gbfgetint32(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " data_read: Major Version %d Minor Version %d Data Stream Version %d\n",
fatal(MYNAME ": input file is from an unsupported version of the USR format (must be version 4)\n");
}
- text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 1);
+ int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 1);
if (text_len > 0 && global_opts.debug_level >= 1) {
buff[text_len] = '\0';
printf(MYNAME " file title: %s\n", buff);
}
/* for now we won't use these for anything */
- create_date = gbfgetint32(file_in);
+ unsigned int create_date = gbfgetint32(file_in);
(void) create_date;
- create_time = gbfgetint32(file_in);
+ unsigned int create_time = gbfgetint32(file_in);
(void) create_time;
- byte = gbfgetc(file_in); /* unused, apparently */
+ unsigned char byte = gbfgetc(file_in); /* unused, apparently */
(void) byte;
- serial_num = gbfgetint32(file_in);
+ unsigned int serial_num = gbfgetint32(file_in);
if (global_opts.debug_level >= 1) {
printf(MYNAME " device serial number %u\n", serial_num);
}
static void
lowranceusr4_write_wpt_uids(const Waypoint* wpt)
{
- int waypt_idx;
-
/* find the index of wpt in our table */
- waypt_idx = lowranceusr4_find_waypt_index(wpt);
+ int waypt_idx = lowranceusr4_find_waypt_index(wpt);
if (global_opts.debug_level >= 2) {
if (waypt_idx > waypt_table_ct) {
printf(MYNAME " WARNING: failed finding waypoint %s in waypoint table\n",
static void
data_write()
{
- short int MajorVersion, MinorVersion;
- int DataStreamVersion;
time_t now;
- struct tm* now_tm;
char buf[256];
setshort_length(mkshort_handle, 15);
- MajorVersion = 4;
- MinorVersion = 0;
- DataStreamVersion = 10;
+ short int MajorVersion = 4;
+ short int MinorVersion = 0;
+ int DataStreamVersion = 10;
gbfputint16(MajorVersion, file_out);
gbfputint16(MinorVersion, file_out);
/* date string */
now = time(nullptr);
- now_tm = gmtime(&now);
+ struct tm* now_tm = gmtime(&now);
sprintf(buf, "%d/%d/%d", now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_year+1900);
lowranceusr4_writestr(buf, file_out, 1);
char* buff;
while ((buff = gbfgetstr(maggeofile_in))) {
- Waypoint* wpt_tmp;
- geocache_data* gcdata;
char* s = nullptr;
- int fld;
buff = lrtrim(buff);
if (*buff == '\0') {
}
buff += 9; /* skip field no. 1 */
- fld = 1;
+ int fld = 1;
- wpt_tmp = new Waypoint;
- gcdata = wpt_tmp->AllocGCData();
+ Waypoint* wpt_tmp = new Waypoint;
+ geocache_data* gcdata = wpt_tmp->AllocGCData();
while ((s = csv_lineparse(buff, ",", "", fld++))) {
buff = nullptr;
void
append(char* buf, const char* str)
{
- char* cleansed1, *cleansed2;
+ char* cleansed2;
strcat(buf, ",");
return;
}
- cleansed1 = xstrdup(str);
+ char* cleansed1 = xstrdup(str);
#if FIRMWARE_DOES_88591
/* Actually, this function needs needs refactored... */
cleansed2 = xstrdup(cleansed1);
maggeo_waypt_pr(const Waypoint* waypointp)
{
char obuf[4096];
- double ilon, ilat;
- double lon, lat;
- int lon_deg, lat_deg;
const char* ctype = nullptr;
- QString placer;
- ilat = waypointp->latitude;
- ilon = waypointp->longitude;
+ double ilat = waypointp->latitude;
+ double ilon = waypointp->longitude;
- lon = fabs(ilon);
- lat = fabs(ilat);
+ double lon = fabs(ilon);
+ double lat = fabs(ilat);
- lon_deg = lon;
- lat_deg = lat;
+ int lon_deg = lon;
+ int lat_deg = lat;
lon = (lon - lon_deg) * 60.0;
lat = (lat - lat_deg) * 60.0;
QString lfounddate = maggeo_fmtdate(waypointp->gc_data->last_found);
QString cname = mkshort(desc_handle,
waypointp->notes.isEmpty() ? waypointp->description : waypointp->notes);
- placer = waypointp->gc_data->placer;
+ QString placer = waypointp->gc_data->placer;
/*
* As of this writing on 05/04, the firmware in the units will
{
unsigned int osum = mag_checksum(buf);
int retry_cnt = 5;
- int i;
char obuf[1000];
if (debug_serial) {
retry:
- i = sprintf(obuf, "$%s*%02X\r\n",buf, osum);
+ int i = sprintf(obuf, "$%s*%02X\r\n",buf, osum);
termwrite(obuf, i);
if (magrxstate == mrs_handon || magrxstate == mrs_awaiting_ack) {
magrxstate = mrs_awaiting_ack;
{
char obuf[200];
char nbuf[200];
- int i;
- unsigned int nsum;
if (is_file) {
return;
}
(void) sprintf(nbuf, "PMGNCSM,%02X", osum);
- nsum = mag_checksum(nbuf);
- i = sprintf(obuf, "$%s*%02X\r\n",nbuf, nsum);
+ unsigned int nsum = mag_checksum(nbuf);
+ int i = sprintf(obuf, "$%s*%02X\r\n",nbuf, nsum);
if (debug_serial) {
warning("ACK WRITE: %s",obuf);
{
char ibuf[512]; /* oliskoli: corrupted data (I've seen descr with a lot
of escaped FFFFFFFF) may need more size */
- int isz;
- unsigned int isum;
- char* isump;
int retrycnt = 20;
retry:
}
- isz = strlen(ibuf);
+ int isz = strlen(ibuf);
if (isz < 5) {
if (debug_serial) {
while (!isprint(ibuf[isz])) {
isz--;
}
- isump = &ibuf[isz-1];
- isum = strtoul(isump, nullptr,16);
+ char* isump = &ibuf[isz-1];
+ unsigned int isum = strtoul(isump, nullptr,16);
if (isum != mag_pchecksum(&ibuf[1], isz-3)) {
if (debug_serial) {
warning("RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf);
if (is_file) {
return gbfgets(ibuf, size, magfile_h);
} else {
- int rc;
- rc = gbser_read_line(serial_handle, ibuf, size, 2000, 0x0a, 0x0d);
+ int rc = gbser_read_line(serial_handle, ibuf, size, 2000, 0x0a, 0x0d);
if (rc != gbser_OK) {
fatal(MYNAME ": Read error\n");
}
static void
mag_serial_init_common(const QString& portname)
{
- time_t now, later;
-
if (is_file) {
return;
}
mag_handon();
}
- now = current_time().toTime_t();
+ time_t now = current_time().toTime_t();
/*
* The 315 can take up to 4.25 seconds to respond to initialization
* commands. Time out on the side of caution.
*/
- later = now + 6;
+ time_t later = now + 6;
got_version = 0;
mag_writemsg("PMGNCMD,VERSION");
void parse_istring(char* istring)
{
int f = 0;
- int n,x;
+ int n;
while (istring[0]) {
char* fp = ifield[f];
- x = sscanf(istring, "%[^,]%n", fp, &n);
+ int x = sscanf(istring, "%[^,]%n", fp, &n);
f++;
if (x) {
istring += n;
Waypoint*
mag_trkparse(char* trkmsg)
{
- double latdeg, lngdeg;
- int alt;
- char altunits;
- char lngdir, latdir;
- int dmy;
int hms;
int fracsecs;
struct tm tm;
- Waypoint* waypt;
- waypt = new Waypoint;
+ Waypoint* waypt = new Waypoint;
memset(&tm, 0, sizeof(tm));
* for us.
*/
parse_istring(trkmsg);
- latdeg = atof(ifield[1]);
- latdir = ifield[2][0];
- lngdeg = atof(ifield[3]);
- lngdir = ifield[4][0];
- alt = atof(ifield[5]);
- altunits = ifield[6][0];
+ double latdeg = atof(ifield[1]);
+ char latdir = ifield[2][0];
+ double lngdeg = atof(ifield[3]);
+ char lngdir = ifield[4][0];
+ int alt = atof(ifield[5]);
+ char altunits = ifield[6][0];
(void)altunits;
sscanf(ifield[7], "%d.%d", &hms, &fracsecs);
/* Field 8 is constant */
/* Field nine is optional track name */
- dmy = atoi(ifield[10]);
+ int dmy = atoi(ifield[10]);
tm.tm_sec = hms % 100;
hms = hms / 100;
/* Explorist has a route name here */
QString rte_name;
if (explorist) {
- char* ca, *ce;
-
- ca = rtemsg + n;
+ char* ca = rtemsg + n;
is_fatal(*ca++ != ',', MYNAME ": Incorrectly formatted route line '%s'", rtemsg);
- ce = strchr(ca, ',');
+ char* ce = strchr(ca, ',');
is_fatal(ce == nullptr, MYNAME ": Incorrectly formatted route line '%s'", rtemsg);
if (ca == ce) {
*/
if (frag == mag_rte_head->nelems) {
queue* elem, *tmp;
- route_head* rte_head;
- rte_head = route_head_alloc();
+ route_head* rte_head = route_head_alloc();
route_add_head(rte_head);
rte_head->rte_num = rtenum;
rte_head->rte_name = rte_name;
QUEUE_FOR_EACH(&mag_rte_head->Q, elem, tmp) {
mag_rte_elem* re = (mag_rte_elem*) elem;
- Waypoint* waypt;
queue* welem, *wtmp;
/*
* Copy route points from temp wpt queue.
*/
QUEUE_FOR_EACH(&rte_wpt_tmp, welem, wtmp) {
- waypt = (Waypoint*)welem;
+ Waypoint* waypt = (Waypoint*)welem;
if (waypt->shortname == re->wpt_name) {
Waypoint* wpt = new Waypoint(*waypt);
route_add_wpt(rte_head, wpt);
char shortname[100];
char descr[256];
char icon_token[100];
- Waypoint* waypt;
- char* icons;
- char* icone;
int i = 0;
descr[0] = 0;
icon_token[0] = 0;
- waypt = new Waypoint;
+ Waypoint* waypt = new Waypoint;
sscanf(trkmsg,"$PMGNWPL,%lf,%c,%lf,%c,%d,%c,%[^,],%[^,]",
&latdeg,&latdir,
&lngdeg,&lngdir,
&alt,&altunits,shortname,descr);
- icone = strrchr(trkmsg, '*');
- icons = strrchr(trkmsg, ',')+1;
+ char* icone = strrchr(trkmsg, '*');
+ char* icons = strrchr(trkmsg, ',')+1;
mag_dequote(descr);
void
mag_waypt_pr(const Waypoint* waypointp)
{
- double lon, lat;
- double ilon, ilat;
- int lon_deg, lat_deg;
char obuf[200];
char ofmtdesc[200];
QString icon_token;
- ilat = waypointp->latitude;
- ilon = waypointp->longitude;
+ double ilat = waypointp->latitude;
+ double ilon = waypointp->longitude;
- lon = fabs(ilon);
- lat = fabs(ilat);
+ double lon = fabs(ilon);
+ double lat = fabs(ilat);
- lon_deg = lon;
- lat_deg = lat;
+ int lon_deg = lon;
+ int lat_deg = lat;
lon = (lon - lon_deg) * 60.0;
lat = (lat - lat_deg) * 60.0;
static
void mag_track_disp(const Waypoint* waypointp)
{
- double ilon, ilat;
- double lon, lat;
- int lon_deg, lat_deg;
char obuf[200];
int hms=0;
int fracsec=0;
int date=0;
- ilat = waypointp->latitude;
- ilon = waypointp->longitude;
+ double ilat = waypointp->latitude;
+ double ilon = waypointp->longitude;
struct tm* tm = nullptr;
if (waypointp->creation_time.isValid()) {
const time_t ct = waypointp->GetCreationTime().toTime_t();
fracsec = 0;
}
- lon = fabs(ilon);
- lat = fabs(ilat);
+ double lon = fabs(ilon);
+ double lat = fabs(ilat);
- lon_deg = lon;
- lat_deg = lat;
+ int lon_deg = lon;
+ int lat_deg = lat;
lon = (lon - lon_deg) * 60.0;
lat = (lat - lat_deg) * 60.0;
mag_route_trl(const route_head* rte)
{
queue* elem, *tmp;
- Waypoint* waypointp;
char obuff[256];
char buff1[64], buff2[64];
char* pbuff;
QString icon_token;
- int i, numlines, thisline;
/* count waypoints for this route */
- i = rte->rte_waypt_ct;
+ int i = rte->rte_waypt_ct;
/* number of output PMGNRTE messages at 2 points per line */
- numlines = (i / 2) + (i % 2);
+ int numlines = (i / 2) + (i % 2);
/* increment the route counter. */
route_out_count++;
- thisline = i = 0;
+ int thisline = i = 0;
QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
- waypointp = (Waypoint*) elem;
+ Waypoint* waypointp = (Waypoint*) elem;
i++;
if (deficon) {
tracking_status.request_terminate = 0;
while (!tracking_status.request_terminate) {
- Waypoint* wpt;
-
- wpt = ivecs->position_ops.rd_position(&tracking_status);
+ Waypoint* wpt = ivecs->position_ops.rd_position(&tracking_status);
if (tracking_status.request_terminate) {
delete wpt;
tr7_read()
{
route_head* trk = nullptr;
- unsigned int magic;
Waypoint* prev = nullptr;
- magic = gbfgetint32(fin);
+ unsigned int magic = gbfgetint32(fin);
if (magic != TR7_TRACK_MAGIC) {
fatal(MYNAME ": Invalid magic number in header (%X, but %X expected)!\n", magic, TR7_TRACK_MAGIC);
}
while (! gbfeof(fin)) {
unsigned char buff[TR7_S_SIZE];
- double lat, lon;
- Waypoint* wpt;
- float speed, course;
gbfread(buff, 1, sizeof(buff), fin);
- lat = (double)le_read32(&buff[TR7_S_LAT]) / 1000000.0;
- lon = (double)le_read32(&buff[TR7_S_LON]) / 1000000.0;
+ double lat = (double)le_read32(&buff[TR7_S_LAT]) / 1000000.0;
+ double lon = (double)le_read32(&buff[TR7_S_LON]) / 1000000.0;
if ((fabs(lat) > 90) || (fabs(lon) > 180)) { /* that really happens */
trk = nullptr;
continue;
}
- speed = KPH_TO_MPS(le_read16(&buff[TR7_S_SPEED]));
- course = 360 - le_read16(&buff[TR7_S_COURSE]);
+ float speed = KPH_TO_MPS(le_read16(&buff[TR7_S_SPEED]));
+ float course = 360 - le_read16(&buff[TR7_S_COURSE]);
if ((speed < 0) || (course > 360) || (course < 0)) {
continue;
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = lat;
wpt->longitude = lon;
mapsend_wpt_read()
{
char tbuf[256];
- int wpt_count, rte_count, rte_num;
char wpt_icon;
Waypoint* wpt_tmp;
- wpt_count = gbfgetint32(mapsend_file_in);
+ int wpt_count = gbfgetint32(mapsend_file_in);
while (wpt_count--) {
wpt_tmp = new Waypoint;
}
/* now read the routes... */
- rte_count = gbfgetint32(mapsend_file_in);
+ int rte_count = gbfgetint32(mapsend_file_in);
while (rte_count--) {
route_head* rte_head = route_head_alloc();
rte_head->rte_name = gbfgetpstr(mapsend_file_in);
/* route # */
- rte_num = gbfgetint32(mapsend_file_in);
+ int rte_num = gbfgetint32(mapsend_file_in);
rte_head->rte_num = rte_num;
/* points this route */
static void
mapsend_track_read()
{
- unsigned int trk_count;
- route_head* track_head;
-
- track_head = route_head_alloc();
+ route_head* track_head = route_head_alloc();
track_head->rte_name = gbfgetpstr(mapsend_file_in);
track_add_head(track_head);
- trk_count = gbfgetuint32(mapsend_file_in);
+ unsigned int trk_count = gbfgetuint32(mapsend_file_in);
while (trk_count--) {
Waypoint* wpt_tmp = new Waypoint;
mapsend_read()
{
mapsend_hdr hdr;
- int type;
- gbsize_t len;
char buf[3];
/*
* strings, each member has to be read in one at a time. Grrr.
*/
- len = gbfread(&hdr, 1, sizeof(hdr), mapsend_file_in);
+ gbsize_t len = gbfread(&hdr, 1, sizeof(hdr), mapsend_file_in);
is_fatal(len < sizeof(hdr), MYNAME ": No mapsend or empty file!");
- type = le_read16(&hdr.ms_type);
+ int type = le_read16(&hdr.ms_type);
strncpy(buf, hdr.ms_version, 2);
buf[2] = '\0';
static void
mapsend_waypt_pr(const Waypoint* waypointp)
{
- double falt;
static int cnt = 0;
QString sn = global_opts.synthesize_shortnames ?
mkshort_from_wpt(mkshort_handle, waypointp) :
gbfputc(c, mapsend_file_out);
gbfputc(1, mapsend_file_out);
- falt = waypointp->altitude;
+ double falt = waypointp->altitude;
if (falt == unknown_alt) {
falt = 0;
}
mapsend_route_disp(const Waypoint* waypointp)
{
unsigned char c;
- QString iconp;
route_wp_count++;
gbfputdbl(-waypointp->latitude, mapsend_file_out);
if (!waypointp->icon_descr.isNull()) {
- iconp = mag_find_token_from_descr(waypointp->icon_descr);
+ QString iconp = mag_find_token_from_descr(waypointp->icon_descr);
if (1 == iconp.size()) {
c = iconp[0].toLatin1() - 'a';
} else {
*/
const char* verstring = "30";
queue* elem, *tmp;
- int i;
mapsend_hdr hdr = {13, {'4','D','5','3','3','3','3','4',' ','M','S'},
{'3','0'}, ms_type_track, {0, 0, 0}
};
gbfputpstr(tname, mapsend_file_out);
/* total nodes (waypoints) this track */
- i = 0;
+ int i = 0;
QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) {
i++;
}
static void mapsend_track_disp(const Waypoint* wpt)
{
unsigned char c;
- int32_t t;
static int last_time;
/*
*
* This is rumoured (but yet unconfirmed) to be fixed in f/w 5.12.
*/
- t = wpt->GetCreationTime().toTime_t();
+ int32_t t = wpt->GetCreationTime().toTime_t();
if (t < last_time) {
t = last_time;
}
mps_fileHeader_r(gbfile* mps_file, int* mps_ver)
{
char hdr[100];
- int reclen;
mps_readstr(mps_file, hdr, sizeof(hdr));
if (strcmp(hdr, "MsRcd")) {
fatal(MYNAME ": This doesn't look like a mapsource file.\n");
}
/* Read record length of "format details" section */
- reclen = gbfgetint32(mps_file);
+ int reclen = gbfgetint32(mps_file);
/* Read the "format details" in plus the trailing null */
gbfread(hdr, 3, 1, mps_file);
if (hdr[0] != 'D') {
mps_fileHeader_w(gbfile* mps_file, int mps_ver)
{
char hdr[100];
- int reclen;
strcpy(hdr, "MsRc");
gbfwrite(hdr, 4, 1, mps_file);
}
hdr[2] = 0;
- reclen = 2; /* this is 3 byte record */
+ int reclen = 2; /* this is 3 byte record */
gbfputint32(reclen, mps_file);
gbfwrite(hdr, 3, 1, mps_file); /* reclen + 1 */
static void
mps_mapsetname_r(gbfile* mps_file, int mps_ver)
{
- int reclen;
-
(void)mps_ver;
/* At the moment we're not doing anything with mapsetnames, but here's the template code as if we were
gbfread(&mapsetnameAutonameFlag, 1, 1, mps_file); */
gbfseek(mps_file, -5, SEEK_CUR);
- reclen = gbfgetint32(mps_file);
+ int reclen = gbfgetint32(mps_file);
gbfseek(mps_file, reclen+1, SEEK_CUR);
return;
}
mps_mapsetname_w(gbfile* mps_file, int mps_ver)
{
char hdr[100];
- int reclen;
(void)mps_ver;
hdr[0] = 'V'; /* mapsetname start of record indicator */
hdr[1] = 0; /* zero length null terminated string */
hdr[2] = 1; /* mapsetname autoname flag set to DO autoname */
- reclen = 2; /* three bytes of the V record */
+ int reclen = 2; /* three bytes of the V record */
gbfputint32(reclen, mps_file);
gbfwrite(hdr, 3, 1, mps_file); /* reclen + 1 */
}
static void
mps_waypoint_w(gbfile* mps_file, int mps_ver, const Waypoint* wpt, const bool isRouteWpt)
{
- int reclen;
- int lat, lon;
- int icon;
- char* ascii_description;
char zbuf[25];
char ffbuf[25];
int display = 1;
double mps_proximity = (mpsuseprox ? WAYPT_GET(wpt, proximity, unknown_alt) : unknown_alt);
double mps_depth = unknown_alt;
- lat = GPS_Math_Deg_To_Semi(wpt->latitude);
- lon = GPS_Math_Deg_To_Semi(wpt->longitude);
+ int lat = GPS_Math_Deg_To_Semi(wpt->latitude);
+ int lon = GPS_Math_Deg_To_Semi(wpt->longitude);
if (WAYPT_HAS(wpt, depth) && mpsusedepth) {
mps_depth = wpt->depth;
}
memset(ffbuf, 0xff, sizeof(ffbuf));
/* might need to change this to handle version dependent icon handling */
- icon = gt_find_icon_number_from_desc(wpt->icon_descr, MAPSOURCE);
+ int icon = gt_find_icon_number_from_desc(wpt->icon_descr, MAPSOURCE);
if (get_cache_icon(wpt)) {
icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), MAPSOURCE);
}
icon = mps_converted_icon_number(icon, mps_ver, MAPSOURCE);
/* two NULL (0x0) bytes at end of each string */
- ascii_description = xstrdup(wpt->description);
- reclen = ident.length() + strlen(ascii_description) + 2;
+ char* ascii_description = xstrdup(wpt->description);
+ int reclen = ident.length() + strlen(ascii_description) + 2;
if ((mps_ver == 4) || (mps_ver == 5)) {
/* v4.06 & V5.0*/
reclen += 85; /* "W" (1) + strlen(name) + NULL (1) + class(4) + country(sz) +
int lon = 0;
char rte_autoname;
int interlinkStepCount;
- int thisInterlinkStep;
unsigned int mpsclass;
route_head* rte_head;
/* take two off the count since we separately read the start and end parts of the link */
/* MRCB 2004/09/15 - NOPE, sorry, this needs to one, since interlink steps can be > 0 */
- for (thisInterlinkStep = interlinkStepCount - 1; thisInterlinkStep > 0; thisInterlinkStep--) {
+ for (int thisInterlinkStep = interlinkStepCount - 1; thisInterlinkStep > 0; thisInterlinkStep--) {
/* Could do this by doing a calculation on length of each co-ordinate and just doing one read
but doing it this way makes it easier in the future to make use of this data */
lat = gbfgetint32(mps_file);
static void
mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte)
{
- unsigned int reclen;
- unsigned int rte_datapoints;
- int rname_len;
char* rname;
char hdr[20];
char zbuf[20];
- Waypoint* testwpt;
time_t uniqueValue = 0;
- int allWptNameLengths;
double maxlat=-90.0;
double maxlon=-180.0;
double maxalt=unknown_alt;
double minalt=-unknown_alt;
- int lat;
- int lon;
-
queue* elem, *tmp;
prevRouteWpt = nullptr; /* clear the stateful flag used to know when the start of route wpts happens */
memset(zbuf, 0, sizeof(zbuf));
/* total nodes (waypoints) this route */
- rte_datapoints = 0;
- allWptNameLengths = 0;
+ unsigned int rte_datapoints = 0;
+ int allWptNameLengths = 0;
if (rte->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */
QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
- testwpt = (Waypoint*)elem;
+ Waypoint* testwpt = (Waypoint*)elem;
if (rte_datapoints == 0) {
uniqueValue = testwpt->GetCreationTime().toTime_t();
}
rname = xstrdup(rte->rte_name);
}
- rname_len = strlen(rname);
- reclen = rname_len + 42; /* "T" (1) + strlen(tname) + NULL (1) + autoname flag (2) +
+ int rname_len = strlen(rname);
+ unsigned int reclen = rname_len + 42; /* "T" (1) + strlen(tname) + NULL (1) + autoname flag (2) +
route lat lon max (2x4) + route max alt (9) +
route lat lon min (2x4) + route min alt (9) +
num route datapoints value (4) */
hdr[2] = 0; /* MSB of don't autoname */
gbfwrite(hdr, 3, 1, mps_file); /* NULL string terminator + route autoname flag */
- lat = GPS_Math_Deg_To_Semi(maxlat);
- lon = GPS_Math_Deg_To_Semi(maxlon);
+ int lat = GPS_Math_Deg_To_Semi(maxlat);
+ int lon = GPS_Math_Deg_To_Semi(maxlon);
gbfputint32(lat, mps_file);
gbfputint32(lon, mps_file);
static void
mps_routedatapoint_w(gbfile* mps_file, int mps_ver, const Waypoint* rtewpt)
{
- int lat;
- int lon;
char zbuf[20];
char ffbuf[20];
- int reclen;
int maxlat;
int maxlon;
double maxalt=unknown_alt;
double minalt=-unknown_alt;
- double mps_altitude;
- Waypoint* wptfound;
-
memset(zbuf, 0, sizeof(zbuf));
memset(ffbuf, 0xff, sizeof(ffbuf));
if (prevRouteWpt != nullptr) {
/* output the route link details */
- reclen = 2;
+ int reclen = 2;
gbfputint32(reclen, mps_file);
/* output end point 1 */
- lat = GPS_Math_Deg_To_Semi(prevRouteWpt->latitude);
- lon = GPS_Math_Deg_To_Semi(prevRouteWpt->longitude);
+ int lat = GPS_Math_Deg_To_Semi(prevRouteWpt->latitude);
+ int lon = GPS_Math_Deg_To_Semi(prevRouteWpt->longitude);
gbfputint32(lat, mps_file);
gbfputint32(lon, mps_file);
- mps_altitude = prevRouteWpt->altitude;
+ double mps_altitude = prevRouteWpt->altitude;
if (mps_altitude == unknown_alt) {
gbfwrite(zbuf, 9, 1, mps_file);
} else {
gbfputs(ident, mps_file);
gbfwrite(zbuf, 1, 1, mps_file); /* NULL termination to ident */
- wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, ident);
+ Waypoint* wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, ident);
if (wptfound != nullptr) {
zbuf[0] = (char)MPSHIDDENROUTEWPTCLASS;
} else {
static void
mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk)
{
- unsigned int reclen;
- unsigned int trk_datapoints;
unsigned int colour = 0; /* unknown colour */
- int tname_len;
char* tname;
char hdr[20];
- Waypoint* testwpt;
time_t uniqueValue = 0;
queue* elem, *tmp;
(void)mps_ver;
/* total nodes (waypoints) this track */
- trk_datapoints = 0;
+ unsigned int trk_datapoints = 0;
if (trk->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */
QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) {
if (trk_datapoints == 0) {
- testwpt = (Waypoint*)elem;
+ Waypoint* testwpt = (Waypoint*)elem;
uniqueValue = testwpt->GetCreationTime().toTime_t();
}
trk_datapoints++;
tname = xstrdup(trk->rte_name);
}
- tname_len = strlen(tname);
- reclen = tname_len + 11; /* "T" (1) + strlen(tname) + NULL (1) + display flag (1) + colour (4) +
+ int tname_len = strlen(tname);
+ unsigned int reclen = tname_len + 11; /* "T" (1) + strlen(tname) + NULL (1) + display flag (1) + colour (4) +
num track datapoints value (4) */
reclen += (trk_datapoints * 31) - 1; /* lat (4) + lon (4) + alt (9) + date (5) + depth (9) ;*/
static void
mps_write()
{
- int short_length;
Waypoint* wpt;
route_head* rte;
route_head* trk;
unsigned int tocopy;
unsigned int block;
- long tempFilePos;
unsigned int mpsWptClass;
unsigned char copybuf[8192];
- short_length = atoi(snlen);
+ int short_length = atoi(snlen);
if (mpsmergeout) {
/* need to skip over the merging header and test merge version */
gbfwrite(&reclen, 4, 1, mps_file_out); /* write out untouched */
gbfwrite(&recType, 1, 1, mps_file_out);
- tempFilePos = gbftell(mps_file_temp);
+ long tempFilePos = gbftell(mps_file_temp);
/* need to read in the waypoint info only because later we may need to check for uniqueness
since we're here because the user didn't request waypoints, this should be acceptable */
mps_waypoint_r(mps_file_temp, mps_ver_temp, &wpt, &mpsWptClass);
is_unique(mkshort_handle_imp* h, char* name)
{
queue* e, *t;
- int hash;
- hash = hash_string(name);
+ int hash = hash_string(name);
QUEUE_FOR_EACH(&h->namelist[hash], e, t) {
uniq_shortname* z = (uniq_shortname*) e;
if (0 == case_ignore_strcmp(z->orig_shortname, name)) {
uniq_shortname* s;
while ((s = is_unique(h, name))) {
- int dl;
char tbuf[10];
size_t l = strlen(name);
s->conflictctr++;
- dl = sprintf(tbuf, ".%d", s->conflictctr);
+ int dl = sprintf(tbuf, ".%d", s->conflictctr);
if (l + dl < h->target_len) {
name = (char*) xrealloc(name, l + dl + 1);
*replaced = 0;
for (int l = strlen(istring); l > start; l--) {
if (strchr(vowels, istring[l-1])) {
- char* ostring;
/* If vowel is the first letter of a word, keep it.*/
if (istring[l-2] == ' ') {
continue;
}
- ostring = xstrdup(istring);
+ char* ostring = xstrdup(istring);
strncpy(&ostring[l-1], &istring[l], 1+strlen(istring)-l);
ostring[strlen(istring)-1] = 0;
*replaced = 1;
void
replace_constants(char* s)
{
- struct replacements* r;
int origslen = strlen(s);
- for (r = replacements; r->orig; r++) {
+ for (struct replacements* r = replacements; r->orig; r++) {
int rl = strlen(r->orig);
/*
* If word is in replacement list and preceeded by a
#endif
{
char* ostring;
- char* nstring;
char* tstring;
char* cp;
- char* np;
int i, l, replaced;
- size_t nlen;
mkshort_handle_imp* hdl = (mkshort_handle_imp*) h;
if (hdl->is_utf8) {
if ((strlen(ostring) > hdl->target_len + 4) &&
(strncmp(ostring, "The ", 4) == 0 ||
strncmp(ostring, "the ", 4) == 0)) {
- nstring = xxstrdup(ostring + 4, file, line);
+ char* nstring = xxstrdup(ostring + 4, file, line);
xfree(ostring);
ostring = nstring;
}
* Walk in the Woods 2.
*/
- np = ostring + strlen(ostring);
+ char* np = ostring + strlen(ostring);
while ((np != ostring) && *(np-1) && isdigit(*(np-1))) {
np--;
}
- nlen = strlen(np);
+ size_t nlen = strlen(np);
/*
* Now brutally truncate the resulting string, preserve trailing
mmo_readstr()
{
char* res;
- signed int len;
- len = (unsigned)gbfgetc(fin);
+ signed int len = (unsigned)gbfgetc(fin);
if (len == 0xFF) {
// Next two bytes are either the length (strings longer than 254 chars)
// or FE then FF (which is -2) meaning a UTF-16 string
res = (char*) xmalloc(len*2 + 1); // bigger to allow for utf-8 expansion
for (signed int ii = 0; ii<len; ii++) {
char utf8buf[8];
- int utf8len;
unsigned int ch = gbfgetint16(fin);
// convert to utf-8, possibly multiple bytes
- utf8len = cet_ucs4_to_utf8(utf8buf, sizeof(utf8buf), ch);
+ int utf8len = cet_ucs4_to_utf8(utf8buf, sizeof(utf8buf), ch);
for (signed int jj = 0; jj < utf8len; jj++) {
res[resbytes++] = utf8buf[jj];
}
static int
mmo_fillbuf2(void* buf, const gbsize_t bufsz, const gbsize_t count, const int need_all)
{
- gbsize_t res;
-
if (count > (unsigned int)bufsz) {
fatal(MYNAME ": Internal error (bufsz too small)!\n");
}
memset(buf, 0xFF, count);
- res = gbfread(buf, 1, count, fin);
+ gbsize_t res = gbfread(buf, 1, count, fin);
if (need_all && (res < count)) {
fatal(MYNAME ": Unexpected end of file!\n");
}
static mmo_data_t*
mmo_register_object(const int objid, const void* ptr, const gpsdata_type type)
{
- mmo_data_t* data;
-
- data = (mmo_data_t*) xcalloc(1, sizeof(*data));
+ mmo_data_t* data = (mmo_data_t*) xcalloc(1, sizeof(*data));
data->data = const_cast<void*>(ptr);
data->visible = 1;
data->locked = 0;
static mmo_data_t*
mmo_get_object(const uint16_t objid)
{
- int key;
-
- key = objid | 0x8000;
+ int key = objid | 0x8000;
if (!objects.contains(key)) {
#ifdef MMO_DBG
gbfseek(fin, -2, SEEK_CUR);
int marker = gbfgetuint16(fin);
if (marker & 0x8000) {
- mmo_data_t* tmp;
-
DBG(("mmo_read_category", "reading category object\n"));
gbfseek(fin, -2, SEEK_CUR);
- tmp = mmo_read_object();
+ mmo_data_t* tmp = mmo_read_object();
if (data) {
data->category = tmp->name;
}
DBG((sobj, "unknown value = 0x%04X\n", u16));
while ((icon_id = gbfgetuint32(fin))) {
- char* name;
(void) gbfgetuint32(fin);
(void) gbfgetuint32(fin);
- name = mmo_readstr();
+ char* name = mmo_readstr();
DBG((sobj, "bitmap(0x%08X) = \"%s\"\n", icon_id, name));
mmo_register_icon(icon_id, name);
xfree(name);
const char* sobj = "CObjWaypoint";
#endif
Waypoint* wpt;
- time_t time;
- int rtelinks;
mmo_data_t** rtelink = nullptr;
- char* str;
char buf[16];
- int i, ux;
+ int i;
DBG((sobj, ":-----------------------------------------------------\n"));
DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n",
data->data = wpt = new Waypoint;
wpt->shortname = QString::fromLatin1(data->name);
- time = data->mtime;
+ time_t time = data->mtime;
if (! time) {
time = data->ctime;
}
}
if (mmo_version >= 0x18) {
- uint16_t u16;
- u16 = gbfgetuint16(fin);
+ uint16_t u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16));
u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16));
DBG((sobj, "trackpoint %d/%d coordinates = %f / %f\n", ctp+1,tp, wpt->latitude, wpt->longitude));
- rtelinks = gbfgetuint16(fin);
+ int rtelinks = gbfgetuint16(fin);
if (rtelinks > 0) {
rtelink = (mmo_data_t**) xcalloc(sizeof(*rtelink), rtelinks);
}
- str = mmo_readstr(); /* descr + url */
+ char* str = mmo_readstr(); /* descr + url */
if (strncmp(str, "_FILE_ ", 7) == 0) {
- char* cx, *cend;
-
- cx = lrtrim(str + 7);
- cend = strchr(cx, '\n');
+ char* cx = lrtrim(str + 7);
+ char* cend = strchr(cx, '\n');
if (cend == nullptr) {
cend = cx + strlen(cx);
}
xfree(str);
}
- ux = gbfgetuint32(fin);
+ int ux = gbfgetuint32(fin);
DBG((sobj, "proximity type = %d\n", ux));
(void) ux;
const char* sobj = "CObjRoute";
#endif
route_head* rte;
- int ux;
DBG((sobj, ":-----------------------------------------------------\n"));
DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n",
route_add_head(rte);
if (mmo_version >= 0x18) {
- uint16_t u16;
- u16 = gbfgetuint16(fin);
+ uint16_t u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16));
u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16));
(void) u16;
}
- ux = gbfgetc(fin); /* line label */
+ int ux = gbfgetc(fin); /* line label */
DBG((sobj, "line label = %d\n", ux));
(void) ux;
}
while (data->left > 0) {
- mmo_data_t* tmp;
-
DBG((sobj, "read next waypoint\n"));
- tmp = mmo_read_object();
+ mmo_data_t* tmp = mmo_read_object();
if (tmp && tmp->data && (tmp->type == wptdata)) {
Waypoint* wpt;
#ifdef MMO_DBG
const char* sobj = "CObjTrack";
#endif
- int tp;
- route_head* trk;
DBG((sobj, ":-----------------------------------------------------\n"));
DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n",
data->name, data->visible ? "yes" : "NO", data->objid));
- trk = route_head_alloc();
+ route_head* trk = route_head_alloc();
trk->rte_name = data->name;
track_add_head(trk);
if (mmo_version >= 0x18) {
- uint16_t u16;
- u16 = gbfgetuint16(fin);
+ uint16_t u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16));
u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16));
(void) u16;
}
- tp = gbfgetint16(fin);
+ int tp = gbfgetint16(fin);
DBG((sobj, "track has %d point(s)\n", tp));
for (int ctp = 0; ctp < tp; ctp++) {
- Waypoint* wpt;
- char unk;
-
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = gbfgetdbl(fin);
wpt->longitude = gbfgetdbl(fin);
DBG((sobj, "coordinates = %f / %f\n", wpt->latitude, wpt->longitude));
- unk = gbfgetc(fin);
+ char unk = gbfgetc(fin);
DBG((sobj, "Unknown = 0x%02X (%d)\n", unk, unk));
wpt->SetCreationTime(gbfgetint32(fin));
wpt->altitude = gbfgetflt(fin);
if (unk != 0) {
- uint16_t ux;
- ux = gbfgetuint16(fin);
+ uint16_t ux = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (%d)\n", ux, ux));
(void) ux;
if (unk > 1) {
}
if (mmo_version > 0) {
- uint32_t u32;
-
- u32 = gbfgetuint32(fin); /* Min. update interval */
+ uint32_t u32 = gbfgetuint32(fin); /* Min. update interval */
DBG((sobj, "min. update interval = %d\n", u32));
u32 = gbfgetuint32(fin); /* unknown */
DBG((sobj, "unknown value = 0x%08X (%d)\n", u32, u32));
}
if (mmo_version >= 0x12) {
- char u8;
-
- u8 = gbfgetc(fin);
+ char u8 = gbfgetc(fin);
DBG((sobj, "line width = %d - (since 0x12)\n", u8));
u8 = gbfgetc(fin);
DBG((sobj, "line style = %d - (since 0x12)\n", u8));
trk->line_color.opacity = 255 - (u8 * 51);
if (mmo_version >= 0x16) {
- uint16_t u16;
- char* text;
-
// XXX ARB was u8 = gbfgetc(fin); but actually a string
- text = mmo_readstr();
+ char* text = mmo_readstr();
DBG((sobj, "text = \"%s\"\n", text));
xfree(text);
- u16 = gbfgetuint16(fin);
+ uint16_t u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x16)\n", u16));
u16 = gbfgetuint16(fin);
DBG((sobj, "unknown value = 0x%04X (since 0x16)\n", u16));
const char* sobj = "CObjText";
#endif
char buf[28];
- double lat, lon;
- char* text, *font;
DBG((sobj, ":-----------------------------------------------------\n"));
DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n",
data->name, data->visible ? "yes" : "NO", data->objid));
- lat = gbfgetdbl(fin);
- lon = gbfgetdbl(fin);
+ double lat = gbfgetdbl(fin);
+ double lon = gbfgetdbl(fin);
DBG((sobj, "coordinates = %f / %f\n", lat, lon));
(void) lat;
(void) lon;
- text = mmo_readstr();
+ char* text = mmo_readstr();
DBG((sobj, "text = \"%s\"\n", text));
xfree(text);
mmo_fillbuf(buf, 28, 1);
- font = mmo_readstr();
+ char* font = mmo_readstr();
DBG((sobj, "font = \"%s\"\n", font));
xfree(font);
const char* sobj = "CObjCurrentPosition";
#endif
char buf[24];
- double lat, lon;
DBG((sobj, ":-----------------------------------------------------\n"));
DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n",
data->name, data->visible ? "yes" : "NO", data->objid));
- lat = gbfgetdbl(fin);
- lon = gbfgetdbl(fin);
+ double lat = gbfgetdbl(fin);
+ double lon = gbfgetdbl(fin);
DBG((sobj, "coordinates = %f / %f\n", lat, lon));
(void) lat;
(void) lon;
}
if (mmo_version >= 0x14) {
- char* name;
-
- name = mmo_readstr();
+ char* name = mmo_readstr();
DBG((sobj, "name = \"%s\"\n", name));
xfree(name);
// XXX ARB was just: mmo_fillbuf(buf, 13, 1);
static mmo_data_t*
mmo_read_object()
{
- int objid;
mmo_data_t* data = nullptr;
// There are three cases:
// a new object; or
// a back reference to an object that appears earlier in the file.
- objid = gbfgetuint16(fin);
+ int objid = gbfgetuint16(fin);
if (objid == 0xFFFF) {
- uint16_t version;
- char* sobj;
- int len;
DBG(("mmo_read_object", "Registering new object type\n"));
objid = mmo_object_id++;
- version = gbfgetuint16(fin);
+ uint16_t version = gbfgetuint16(fin);
is_fatal(version != mmo_version, MYNAME ": Invalid version identifier!\n");
- len = gbfgetint16(fin);
+ int len = gbfgetint16(fin);
- sobj = (char*) xmalloc(len + 1);
+ char* sobj = (char*) xmalloc(len + 1);
sobj[len] = '\0';
gbfread(sobj, len, 1, fin);
DBG(("mmo_read_object", "%s\n", sobj));
data->name = mmo_readstr();
if (objid != cat_object_id) {
- uint32_t obj_type;
data->ctime = gbfgetuint32(fin);
data->mtime = gbfgetuint32(fin);
data->locked = gbfgetc(fin);
data->visible = gbfgetc(fin);
- obj_type = gbfgetuint32(fin);
+ uint32_t obj_type = gbfgetuint32(fin);
(void) obj_type;
#ifdef MMO_DBG
uint32_t expected_type = 0xFFFFFFFF;
static void
mmo_rd_init(const QString& fname)
{
- int i;
-
fin = gbfopen_le(fname, "rb", MYNAME);
ico_object_id = pos_object_id = txt_object_id = cat_object_id = 0;
mmo_object_id = 0x8001;
- i = 0;
+ int i = 0;
while (mmo_icon_value_table[i].icon) {
mmo_register_icon(mmo_icon_value_table[i].value, mmo_icon_value_table[i].icon);
i++;
#ifdef MMO_DBG
const char* sobj = "main";
#endif
- gbfile* fx;
- int i;
/* copy file to memory stream (needed for seek-ops and piped commands) */
DBG(("main", "loading file \"%s\".\n", fin->name));
- fx = gbfopen(nullptr, "wb", MYNAME);
+ gbfile* fx = gbfopen(nullptr, "wb", MYNAME);
gbfcopyfrom(fx, fin, 0x7FFFFFFF);
gbfrewind(fx);
gbfclose(fin);
mmo_obj_ct = gbfgetuint16(fin);
DBG((sobj, "number of objects = %d\n", mmo_obj_ct));
- i = gbfgetuint16(fin);
+ int i = gbfgetuint16(fin);
if (i != 0xFFFF) {
fatal(MYNAME ": Marker not equal to 0xFFFF!\n");
}
static void
mmo_write_category(const char* sobj, const char* name)
{
- uint16_t nr;
QString key = QString::fromUtf8(name);
if (category_names.contains(key)) {
- nr = category_names.value(key);
+ uint16_t nr = category_names.value(key);
gbfputuint16(nr & 0x7FFF, fout);
} else {
mmo_write_obj_mark(sobj, name);
mmo_write_obj_head(const char* sobj, const char* name, const time_t ctime,
const uint32_t obj_type)
{
- int res;
-
- res = mmo_write_obj_mark(sobj, name);
+ int res = mmo_write_obj_mark(sobj, name);
gbfputuint32(ctime, fout);
gbfputuint32(ctime, fout);
mmo_write_wpt_cb(const Waypoint* wpt)
{
QString str;
- QString cx;
- int objid;
- time_t time;
int icon = 0;
- mmo_data_t* data;
- time = wpt->GetCreationTime().toTime_t();
+ time_t time = wpt->GetCreationTime().toTime_t();
if (time < 0) {
time = 0;
}
}
DBG(("write", "waypoint \"%s\"\n", wpt->shortname ? wpt->shortname : "Mark"));
- objid = mmo_write_obj_head("CObjWaypoint",
- wpt->shortname.isEmpty() ? "Mark" : CSTRc(wpt->shortname), time, obj_type_wpt);
- data = mmo_register_object(objid, wpt, wptdata);
+ int objid = mmo_write_obj_head("CObjWaypoint",
+ wpt->shortname.isEmpty() ? "Mark" : CSTRc(wpt->shortname), time, obj_type_wpt);
+ mmo_data_t* data = mmo_register_object(objid, wpt, wptdata);
data->refct = 1;
mmo_write_category("CCategory", (mmo_datatype == rtedata) ? "Waypoints" : "Marks");
str += "\n";
}
- cx = wpt->notes;
+ QString cx = wpt->notes;
if (cx == nullptr) {
cx = wpt->description;
}
static void
mmo_write_rte_head_cb(const route_head* rte)
{
- int objid;
queue* elem, *tmp;
time_t time = 0x7FFFFFFF;
if (time == 0x7FFFFFFF) {
time = gpsbabel_time;
}
- objid = mmo_write_obj_head("CObjRoute",
- rte->rte_name.isEmpty() ? "Route" : CSTRc(rte->rte_name), time, obj_type_rte);
+ int objid = mmo_write_obj_head("CObjRoute",
+ rte->rte_name.isEmpty() ? "Route" : CSTRc(rte->rte_name), time, obj_type_rte);
mmo_register_object(objid, rte, rtedata);
mmo_write_category("CCategory", "Route");
gbfputc(0, fout); /* unknown */
static void
mmo_write_trk_head_cb(const route_head* trk)
{
- int objid;
-
if (trk->rte_waypt_ct <= 0) {
return;
}
- objid = mmo_write_obj_head("CObjTrack",
- trk->rte_name.isEmpty() ? "Track" : CSTRc(trk->rte_name), gpsbabel_time, obj_type_trk);
+ int objid = mmo_write_obj_head("CObjTrack",
+ trk->rte_name.isEmpty() ? "Track" : CSTRc(trk->rte_name), gpsbabel_time, obj_type_trk);
mmo_write_category("CCategory", "Track");
gbfputuint16(trk->rte_waypt_ct, fout);
void
read_line()
{
- int rc;
- char* s;
-
line[0] = '\0';
if (read_mode == rm_file) {
- s = gbfgetstr(ffd);
+ char* s = gbfgetstr(ffd);
if (s == nullptr) {
dbg(1, "EOF reached\n");
download_complete = 1;
}
strncat(line, s, sizeof(line)-1);
} else {
- rc = gbser_read_line(sfd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D);
+ int rc = gbser_read_line(sfd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D);
if (rc != gbser_OK) {
fatal(MYNAME "Serial read failed: %i\n", rc);
}
void
process_packet()
{
-
- int calculated_checksum;
int given_checksum;
if ((strlen(line) < 3) || (line[0] != '$') || (line[strlen(line)-3] != '*')) {
return;
}
- calculated_checksum = calculate_checksum(&line[1], strlen(line) - 1 - 3);
+ int calculated_checksum = calculate_checksum(&line[1], strlen(line) - 1 - 3);
sscanf(&line[strlen(line) - 2], "%02x", &given_checksum);
if (calculated_checksum != given_checksum) {
dbg(1, "Line %i: NMEA Checksum incorrect, expecting %02X\n", packetnum, calculated_checksum);
void
process_pmtklox()
{
-
- char* token;
- char* loxtype;
- int loxsequence;
- uint32_t timestamp;
- char fixtype;
- float latitude;
- float longitude;
- int height;
- uint8_t calculated_checksum;
int hexval;
uint8_t fixbytes[16];
- int bytenum;
- int fixnum;
static Waypoint* trkpt;
static Waypoint* waypt;
- token = strtok(line, ",");
+ char* token = strtok(line, ",");
if ((token == nullptr) || (strcmp(token, "$PMTKLOX") != 0)) {
warning("Line %i: Invalid packet id\n", packetnum);
return;
}
- loxtype = strtok(nullptr, ",");
+ char* loxtype = strtok(nullptr, ",");
if (loxtype == nullptr) {
warning("Line %i: Missing lox type\n", packetnum);
return;
return;
}
- loxsequence = atoi(strtok(nullptr, ","));
+ int loxsequence = atoi(strtok(nullptr, ","));
if (first_loxsequence == -1) {
first_loxsequence = loxsequence;
}
token = strtok(nullptr, ",");
- fixnum = 0;
+ int fixnum = 0;
while (token != nullptr) {
fixnum++;
- bytenum = 0;
- calculated_checksum = 0;
+ int bytenum = 0;
+ uint8_t calculated_checksum = 0;
for (int wordnum = 0; wordnum<4; wordnum++) { // 4 8-byte hex strings per fix
if (token == nullptr) {
dbg(1, "Line %i: Fix %i incomplete data\n", packetnum, fixnum);
continue;
}
- timestamp = le_read32(&fixbytes[0]);
- fixtype = fixbytes[4];
- latitude = le_read_float(&fixbytes[5]);
- longitude = le_read_float(&fixbytes[9]);
- height = le_read16(&fixbytes[13]);
+ uint32_t timestamp = le_read32(&fixbytes[0]);
+ char fixtype = fixbytes[4];
+ float latitude = le_read_float(&fixbytes[5]);
+ float longitude = le_read_float(&fixbytes[9]);
+ int height = le_read16(&fixbytes[13]);
if (fixtype != '\x02') {
dbg(1, "line %i: Fix %i Invalid fix type: %02X\n", packetnum, fixnum, fixtype);
void
process_pmtklog()
{
- int status;
- int type;
-
strtok(line, ",");
printf("Serial#: %s\n", strtok(nullptr, ","));
- type = atoi(strtok(nullptr, ","));
+ int type = atoi(strtok(nullptr, ","));
if (type == 0) {
printf("Type: %i (wrap around when full)\n", type);
} else {
printf("Distance: %s\n", strtok(nullptr, ","));
printf("Speed: %s\n", strtok(nullptr, ","));
- status = atoi(strtok(nullptr, ","));
+ int status = atoi(strtok(nullptr, ","));
if (status == 0) {
printf("Status: %i (enabled)\n", status);
} else {
void
process_pmtk001()
{
- char* cmd;
- char* flag;
-
strtok(line, ",");
- cmd = strtok(nullptr,",");
- flag = strtok(nullptr,",");
+ char* cmd = strtok(nullptr,",");
+ char* flag = strtok(nullptr,",");
switch (atoi(flag)) {
case 0:
void
process_pmtk705()
{
- char* token;
-
- token = strtok(line, ",");
+ char* token = strtok(line, ",");
token = strtok(nullptr,",");
printf("Firmware: %s\n", token);
void
send_command(const char* s, const char* wait_for)
{
- int rc;
time_t starttime;
time_t currtime;
char cmd[100];
- int checksum;
if (read_mode == rm_file) {
dbg(1, "Sending device commands ignored when using file input: %s\n", s);
return;
}
- checksum = calculate_checksum(&s[1], strlen(s)-1);
+ int checksum = calculate_checksum(&s[1], strlen(s)-1);
snprintf(cmd, sizeof(cmd)-1, "%s*%02X\r\n", s, checksum);
- rc = gbser_print(sfd, cmd);
+ int rc = gbser_print(sfd, cmd);
if (rc != gbser_OK) {
fatal(MYNAME ": Write error (%d)\n", rc);
}
int
calculate_checksum(const char* s, int length)
{
- int sum;
- sum = 0;
+ int sum = 0;
for (int i = 0; i<length; i++) {
sum ^= *s++;
static int do_send_cmd(const char* cmd, int cmdLen)
{
- int rc;
-
dbg(6, "Send %s ", cmd);
- rc = gbser_print(fd, cmd);
+ int rc = gbser_print(fd, cmd);
if (rc != gbser_OK) {
fatal(MYNAME ": Write error (%d)\n", rc);
}
static int do_cmd(const char* cmd, const char* expect, char** rslt, time_t timeout_sec)
{
char line[256];
- int len, done, loops, cmd_erase;
+ int len;
int expect_len;
time_t tout;
tout += 1;
}
- cmd_erase = 0;
+ int cmd_erase = 0;
if (strncmp(cmd, CMD_LOG_ERASE, 12) == 0) {
cmd_erase = 1;
if (global_opts.verbose_status || global_opts.debug_level > 0) {
do_send_cmd(cmd, strlen(cmd)); // success or fatal()...
- done = 0;
- loops = 0;
+ int done = 0;
+ int loops = 0;
memset(line, '\0', sizeof(line));
do {
- int rc;
- rc = gbser_read_line(fd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D);
+ int rc = gbser_read_line(fd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D);
if (rc != gbser_OK) {
if (rc == gbser_TIMEOUT && time(nullptr) > tout) {
dbg(2, "NMEA command '%s' timeout !\n", cmd);
} else if (strncmp(line, "$PMTK", 5) == 0) {
/* A quick parser for ACK packets */
if (!cmd_erase && strncmp(line, "$PMTK001,", 9) == 0 && line[9] != '\0') {
- char* pType, *pRslt;
- pType = &line[9];
- pRslt = strchr(&line[9], ',') + 1;
+ char* pType = &line[9];
+ char* pRslt = strchr(&line[9], ',') + 1;
if (memcmp(&cmd[5], pType, 3) == 0 && pRslt != nullptr && *pRslt != '\0') {
int pAck = *pRslt - '0';
if (pAck != 3 && pAck >= 0 && pAck < 4) { // Erase will return '2'
static int mtk_erase()
{
- int log_status;
char* lstatus = nullptr;
- log_status = 0;
+ int log_status = 0;
// check log status - is logging disabled ?
do_cmd(CMD_LOG_STATUS, "PMTK182,3,7,", &lstatus, 2);
if (lstatus) {
{
char cmd[256];
char* line = nullptr;
- unsigned char crc, *data = nullptr;
- int cmdLen, i, len, rc, init_scan, retry_cnt, log_enabled;
- unsigned int j, bsize, scan_bsize, read_bsize_kb, read_bsize, scan_step, ff_len, null_len, chunk_size;
- unsigned int line_size, data_size, data_addr, addr, addr_max, rcvd_addr, rcvd_bsize;
- unsigned long dsize, dpos = 0;
- FILE* dout;
+ unsigned char* data = nullptr;
+ int i;
+ unsigned int bsize;
+ unsigned long dpos = 0;
char* fusage = nullptr;
return;
}
- log_enabled = 0;
- init_scan = 0;
- dout = ufopen(TEMP_DATA_BIN, "r+b");
+ int log_enabled = 0;
+ int init_scan = 0;
+ FILE* dout = ufopen(TEMP_DATA_BIN, "r+b");
if (dout == nullptr) {
dout = ufopen(TEMP_DATA_BIN, "wb");
if (dout == nullptr) {
}
}
fseek(dout, 0L,SEEK_END);
- dsize = ftell(dout);
+ unsigned long dsize = ftell(dout);
if (dsize > 1024) {
dbg(1, "Temp %s file exists. with size %d\n", qPrintable(TEMP_DATA_BIN),
dsize);
}
gb_sleep(100*1000);
- addr_max = 0;
+ unsigned int addr_max = 0;
// get flash usage, current log address..cmd only works if log disabled.
do_cmd("$PMTK182,2,8*33\r\n", "PMTK182,3,8,", &fusage, 2);
if (fusage) {
}
}
- scan_step = 0x10000;
- scan_bsize = 0x0400;
- read_bsize_kb = strtol(OPT_block_size_kb, nullptr, 10);
+ unsigned int scan_step = 0x10000;
+ unsigned int scan_bsize = 0x0400;
+ unsigned int read_bsize_kb = strtol(OPT_block_size_kb, nullptr, 10);
if (errno == ERANGE || read_bsize_kb < 1) {
read_bsize_kb = 1;
} else if (read_bsize_kb > 64) {
read_bsize_kb = 64;
}
- read_bsize = read_bsize_kb * 1024;
+ unsigned int read_bsize = read_bsize_kb * 1024;
dbg(2, "Download block size is %d bytes\n", read_bsize);
if (init_scan) {
bsize = scan_bsize;
} else {
bsize = read_bsize;
}
- addr = 0x0000;
+ unsigned int addr = 0x0000;
- line_size = 2*read_bsize + 32; // logdata as nmea/hex.
- data_size = read_bsize + 32;
+ unsigned int line_size = 2*read_bsize + 32; // logdata as nmea/hex.
+ unsigned int data_size = read_bsize + 32;
if ((line = (char*) xmalloc(line_size)) == nullptr) {
fatal(MYNAME ": Can't allocate %u bytes for NMEA buffer\n", line_size);
}
}
memset(line, '\0', line_size);
memset(data, '\0', data_size);
- retry_cnt = 0;
+ int retry_cnt = 0;
while (init_scan || addr < addr_max) {
// generate - read address NMEA command, add crc.
- crc = 0;
- cmdLen = snprintf(cmd, sizeof(cmd), "$PMTK182,7,%.8x,%.8x", addr, bsize);
+ unsigned char crc = 0;
+ int cmdLen = snprintf(cmd, sizeof(cmd), "$PMTK182,7,%.8x,%.8x", addr, bsize);
for (i=1; i<cmdLen; i++) {
crc ^= cmd[i];
}
do_send_cmd(cmd, cmdLen);
memset(line, '\0', line_size);
- rcvd_addr = addr;
+ unsigned int rcvd_addr = addr;
do {
- rc = gbser_read_line(fd, line, line_size-1, TIMEOUT, 0x0A, 0x0D);
+ int rc = gbser_read_line(fd, line, line_size-1, TIMEOUT, 0x0A, 0x0D);
if (rc != gbser_OK) {
if (rc == gbser_TIMEOUT && retry_cnt < 3) {
dbg(2, "\nRetry %d at 0x%.8x\n", retry_cnt, addr);
} // else
fatal(MYNAME "mtk_read(): Read error (%d)\n", rc);
}
- len = strlen(line);
+ int len = strlen(line);
dbg(8, "Read %d bytes: '%s'\n", len, line);
if (len > 0) {
line[len] = '\0';
if (strncmp(line, "$PMTK182,8", 10) == 0) { // $PMTK182,8,00005000,FFFFFFF
retry_cnt = 0;
- data_addr = strtoul(&line[11], nullptr, 16);
+ unsigned int data_addr = strtoul(&line[11], nullptr, 16);
// fixme - we should check if all data before data_addr is already received
i = 20;
- j = data_addr - addr;
- ff_len = 0; // number of 0xff bytes.
- null_len = 0; // number of 0x00 bytes.
+ unsigned int j = data_addr - addr;
+ unsigned int ff_len = 0; // number of 0xff bytes.
+ unsigned int null_len = 0; // number of 0x00 bytes.
while (i + 3 < len && j < data_size) {
data[j] = (isdigit(line[i])?(line[i]-'0'):(line[i]-'A'+0xA))*0x10 +
(isdigit(line[i+1])?(line[i+1]-'0'):(line[i+1]-'A'+0xA));
j++;
}
rcvd_addr = addr + j;
- chunk_size = rcvd_addr - data_addr;
+ unsigned int chunk_size = rcvd_addr - data_addr;
if (init_scan) {
if (ff_len == chunk_size) { // data in sector - we've found max sector..
addr_max = data_addr;
}
} while (rcvd_addr < addr + bsize);
- rcvd_bsize = rcvd_addr - addr;
+ unsigned int rcvd_bsize = rcvd_addr - addr;
dbg(2, "Received %d bytes\n", rcvd_bsize);
if (init_scan) {
}
addr += rcvd_bsize;
if (global_opts.verbose_status || (global_opts.debug_level >= 2 && global_opts.debug_level < 5)) {
- int perc;
- perc = 100 - 100*(addr_max-addr)/addr_max;
+ int perc = 100 - 100*(addr_max-addr)/addr_max;
if (addr >= addr_max) {
perc = 100;
}
/* Output a single data line in MTK application compatible format - i.e ignore any locale settings... */
static int csv_line(gbfile* csvFile, int idx, unsigned long bmask, struct data_item* itm)
{
- struct tm* ts_tm;
char ts_str[30];
const char* fix_str = "";
- ts_tm = gmtime(&(itm->timestamp));
+ struct tm* ts_tm = gmtime(&(itm->timestamp));
strftime(ts_str, sizeof(ts_str)-1, "%Y/%m/%d,%H:%M:%S", ts_tm);
if (bmask & (1<<VALID)) {
static int mtk_parse(unsigned char* data, int dataLen, unsigned int bmask)
{
static int count = 0;
- int i, sat_id, hspd;
- unsigned char crc, hbuf[4];
+ int sat_id;
+ int hspd;
+ unsigned char hbuf[4];
struct data_item itm;
dbg(5,"Entering mtk_parse, count = %i, dataLen = %i\n", count, dataLen);
}
memset(&itm, 0, sizeof(itm));
- i = 0;
- crc = 0;
+ int i = 0;
+ unsigned char crc = 0;
for (int k = 0; k<32; k++) {
switch (((1<<k) & bmask)) {
case 1<<UTC:
itm.sat_used = data[i+1];
break;
case 1<<SID: {
- int sat_count, sat_idx, sid_size, l;
- int azoffset, snroffset;
+ int sat_count;
+ int sat_idx;
+ int sid_size;
+ int l;
+ int azoffset;
+ int snroffset;
sat_count = le_read16(data + i + 2);
if (sat_count > 32) {
static void file_read()
{
- long fsize, pos;
-// int i, j, k, bLen;
+ // int i, j, k, bLen;
unsigned char buf[512];
memset(buf, '\0', sizeof(buf));
/* Get size of file to parse */
fseek(fl, 0L, SEEK_END);
- fsize = ftell(fl);
+ long fsize = ftell(fl);
if (fsize <= 0) {
fatal(MYNAME ": File has size %ld\n", fsize);
}
*/
int j = 0;
- pos = 0;
+ long pos = 0;
/* get default bitmask, log period/speed/distance */
int bLen = fread(buf, 1, 20, fl);
if (bLen == 20) {
- unsigned int mask, log_period, log_distance, log_speed, log_policy;
- log_policy = le_read16(buf + 6);
+ unsigned int log_policy = le_read16(buf + 6);
if (!(log_policy == 0x0104 || log_policy == 0x0106) && fsize > 0x10000) {
dbg(1, "Invalid initial log policy 0x%.4x - check next block\n", log_policy);
bLen = fread(buf, 1, 20, fl);
log_policy = le_read16(buf + 6);
}
- mask = le_read32(buf + 2);
+ unsigned int mask = le_read32(buf + 2);
if (mtk_device != MTK_LOGGER) { // clear Holux-specific 'low precision' bit
mask &= 0x7fffffffU;
}
- log_period = le_read32(buf + 8);
- log_distance = le_read32(buf + 12);
- log_speed = le_read32(buf + 16);
+ unsigned int log_period = le_read32(buf + 8);
+ unsigned int log_distance = le_read32(buf + 12);
+ unsigned int log_speed = le_read32(buf + 16);
dbg(1, "Default Bitmask %.8x, Log every %.0f sec, %.0f m, %.0f km/h\n",
mask, log_period/10., log_distance/10., log_speed/10.);
{
const QXmlStreamAttributes a = reader.attributes();
Waypoint* wpt_tmp = new Waypoint;
- geocache_data* gc_data;
- gc_data = wpt_tmp->AllocGCData();
+ geocache_data* gc_data = wpt_tmp->AllocGCData();
if (a.hasAttribute("cache_id")) {
int n = a.value("cache_id").toString().toInt();
QString fn = QString("N%1").arg(n, 5, 16, QChar('0'));
static void
ng_convert_datum(Waypoint* wpt)
{
- double lat, lon, east, north, alt;
+ double lat, lon;
- east = (double) WPNC.wp_data.East;
- north = (double) WPNC.wp_data.North;
- alt = (double) WPNC.wp_data.Alt;
+ double east = (double) WPNC.wp_data.East;
+ double north = (double) WPNC.wp_data.North;
+ double alt = (double) WPNC.wp_data.Alt;
GPS_Math_ICS_EN_To_WGS84(east, north, &lat, &lon);
wpt->latitude = lat;
static void
ng_fwrite_wp_data(const QString& s, const QString& d, ng_wp_data_t* wp_data, gbfile* f)
{
- int i;
char z[50];
memset(z, 0, 50);
- i = strlen(STRFROMUNICODE(s));
+ int i = strlen(STRFROMUNICODE(s));
gbfputc(i, f);
gbfwrite(STRFROMUNICODE(s), 1, i, f);
static void
ng_fread_wp_data(char* d, ng_wp_no_comment_t* wpnc, gbfile* f)
{
-
- int i;
-
gbfread(&wpnc->chHeaderLen ,sizeof(wpnc->chHeaderLen), 1, f);
gbfread(&wpnc->strName, wpnc->chHeaderLen, 1, f);
wpnc->strName[wpnc->chHeaderLen] = 0;
gbfread(&wpnc->wp_data.pad2,2, 1, f);
wpnc->wp_data.Alt = gbfgetint32(f);
gbfread(&wpnc->wp_data.CommentLength, 1, 1, f);
- i = (int)wpnc->wp_data.CommentLength;
+ int i = (int)wpnc->wp_data.CommentLength;
/* Read the comment field */
int handle_nak)
{
unsigned size;
- unsigned char* data;
unsigned checksum;
if (read_word() != 0xa2a0) {
fatal(MYNAME ": Protocol error: Packet too short\n");
}
- data = (unsigned char*) xmalloc(size);
+ unsigned char* data = (unsigned char*) xmalloc(size);
if (gbser_read_wait(serial_handle, data, size, SERIAL_TIMEOUT) != size) {
fatal(MYNAME ": Read error reading %d byte payload\n", size);
{
Waypoint** waypts = nullptr;
unsigned char information[32];
- unsigned short total;
if (global_opts.masked_objective & RTEDATAMASK) {
waypts = (Waypoint**) xcalloc(MAX_WAYPOINTS, sizeof(Waypoint*));
sizeof(information), sizeof(information),
FALSE);
- total = le_read16(information + 0);
+ unsigned short total = le_read16(information + 0);
for (unsigned short start = 0; start < total; start += 32) {
unsigned short count = total - start;
unsigned char payload[7];
- unsigned char* waypoints;
if (count > 32) {
count = 32;
write_packet(PID_QRY_WAYPOINTS, payload, sizeof(payload));
- waypoints = (unsigned char*) xmalloc(count * 32);
+ unsigned char* waypoints = (unsigned char*) xmalloc(count * 32);
read_packet(PID_DATA, waypoints, count * 32, count * 32, FALSE);
serial_read_track()
{
unsigned char information[32];
- unsigned int address;
- unsigned short total;
- route_head* track;
write_packet(PID_QRY_INFORMATION, nullptr, 0);
read_packet(PID_DATA, information,
sizeof(information), sizeof(information),
FALSE);
- address = le_read32(information + 4);
- total = le_read16(information + 12);
+ unsigned int address = le_read32(information + 4);
+ unsigned short total = le_read16(information + 12);
- track = route_head_alloc();
+ route_head* track = route_head_alloc();
track_add_head(track);
while (total > 0) {
unsigned short count = total < MAX_READ_TRACKPOINTS ? total : MAX_READ_TRACKPOINTS;
unsigned char payload[7];
- unsigned char* trackpoints;
le_write32(payload + 0, address);
le_write16(payload + 4, count * 32);
write_packet(PID_READ_TRACKPOINTS, payload, sizeof(payload));
- trackpoints = (unsigned char*) xmalloc(count * 32);
+ unsigned char* trackpoints = (unsigned char*) xmalloc(count * 32);
read_packet(PID_DATA, trackpoints, count * 32, count * 32, FALSE);
write_packet(PID_ACK, nullptr, 0);
serial_write_track()
{
unsigned char information[32];
- unsigned int address;
- unsigned short total;
unsigned char data[7];
write_packet(PID_QRY_INFORMATION, nullptr, 0);
sizeof(information), sizeof(information),
FALSE);
- address = le_read32(information + 4);
- total = le_read16(information + 12);
+ unsigned int address = le_read32(information + 4);
+ unsigned short total = le_read16(information + 12);
le_write32(data + 0, address + total * 32);
le_write16(data + 4, track_data_ptr - track_data);
serial_read_routes(Waypoint** waypts)
{
unsigned char information[32];
- unsigned char routec;
write_packet(PID_QRY_INFORMATION, nullptr, 0);
read_packet(PID_DATA, information,
sizeof(information), sizeof(information),
FALSE);
- routec = information[2];
+ unsigned char routec = information[2];
for (unsigned char r = 0; r < routec; r++) {
unsigned char payload[7];
unsigned char routedata[320];
- route_head* route;
le_write32(payload + 0, r);
le_write16(payload + 2, 0);
write_packet(PID_QRY_ROUTE, payload, sizeof(payload));
read_packet(PID_DATA, routedata, 64, sizeof(routedata), FALSE);
- route = route_head_alloc();
+ route_head* route = route_head_alloc();
route->rte_num = routedata[2];
route->rte_name = xstrdup((char*)routedata + 4);
route_add_head(route);
static void
serial_write_route_end(const route_head* route)
{
- unsigned char* data;
- unsigned src;
unsigned char id[1];
- QString rte_name;
- rte_name = route->rte_name;
+ QString rte_name = route->rte_name;
if (rte_name == nullptr) {
rte_name = "NO NAME";
}
fatal(MYNAME ": Route %s too long\n", qPrintable(route->rte_name));
}
- src = (route_id_ptr + MAX_SUBROUTE_LENGTH) / MAX_SUBROUTE_LENGTH;
- data = (unsigned char*) xmalloc(32 + src * 32);
+ unsigned src = (route_id_ptr + MAX_SUBROUTE_LENGTH) / MAX_SUBROUTE_LENGTH;
+ unsigned char* data = (unsigned char*) xmalloc(32 + src * 32);
le_write16(data + 0, 0x2000);
data[2] = 0;
* SSSSSSMM MMMMHHHH Hdddddmm mmmmmmmm
*/
- int months;
struct tm tm;
memset(&tm, 0, sizeof(tm));
tm.tm_min = ((buffer[0] & 0xC0) >> 6) | ((buffer[1] & 0x0F) << 2);
tm.tm_hour = ((buffer[1] & 0xF0) >> 4) | ((buffer[2] & 0x01) << 4);
tm.tm_mday = (buffer[2] & 0x3E) >> 1;
- months = ((buffer[2] & 0xC0) >> 6) | buffer[3] << 2;
+ int months = ((buffer[2] & 0xC0) >> 6) | buffer[3] << 2;
tm.tm_mon = months % 12 - 1;
tm.tm_year = 100 + months / 12;
unsigned int* seg2_addr, unsigned int* seg2_len)
{
unsigned char info[16];
- unsigned int flash_start_addr;
- unsigned int flash_length;
- unsigned int data_start_addr;
- unsigned int next_blank_addr;
write_packet(PID_INFO_DATALOG, nullptr, 0);
read_packet(PID_DATA, info, sizeof(info), sizeof(info), FALSE);
- flash_start_addr = le_read32(info);
- flash_length = le_read32(info + 4);
- data_start_addr = le_read32(info + 8);
- next_blank_addr = le_read32(info + 12);
+ unsigned int flash_start_addr = le_read32(info);
+ unsigned int flash_length = le_read32(info + 4);
+ unsigned int data_start_addr = le_read32(info + 8);
+ unsigned int next_blank_addr = le_read32(info + 12);
if (data_start_addr > next_blank_addr) {
/* usually there are two segments to be read */
static void
serial_read_datalog()
{
- route_head* track;
unsigned int seg1_addr;
unsigned int seg1_len;
unsigned int seg2_addr;
read_datalog_info(&seg1_addr, &seg1_len, &seg2_addr, &seg2_len);
- track = route_head_alloc();
+ route_head* track = route_head_alloc();
track_add_head(track);
if (seg1_len) {
static void
navitel_read_track()
{
- int points;
route_head* trk = nullptr;
- points = gbfgetint32(fin);
+ int points = gbfgetint32(fin);
(void) gbfgetint32(fin); /* unknown */
for (int i = 0; i < points; i++) {
- int lat, lon;
- Waypoint* wpt;
+ int lon = gbfgetint32(fin);
+ int lat = gbfgetint32(fin);
- lon = gbfgetint32(fin);
- lat = gbfgetint32(fin);
-
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = GPS_Math_Semi_To_Deg(lat & 0x7FFFFFFF);
wpt->longitude = GPS_Math_Semi_To_Deg(lon);
static void
navitel_disp_trkpts(const Waypoint* wpt)
{
- int lat, lon;
-
- lat = GPS_Math_Deg_To_Semi(wpt->latitude);
- lon = GPS_Math_Deg_To_Semi(wpt->longitude);
+ int lat = GPS_Math_Deg_To_Semi(wpt->latitude);
+ int lon = GPS_Math_Deg_To_Semi(wpt->longitude);
if (new_track) {
lat |= (1 << 31);
char mac[2 + 17 + 2 + 1]; /* "( " + MAC + " )" + null */
char desc[sizeof ssid - 1 + 15 + 1]; /* room for channel/speed */
double lat = 0, lon = 0;
- Waypoint* wpt_tmp;
int line_no = 0;
int stealth_num = 0, whitespace_num = 0;
long flags = 0;
memset(&tm, 0, sizeof(tm));
while ((ibuf = gbfgetstr(file_in))) {
- char* field;
- int field_num, len, stealth = 0;
+ int len;
+ int stealth = 0;
if ((line++ == 0) && file_in->unicode) {
cet_convert_init(CET_CHARSET_UTF8, 1);
continue;
}
- field_num = 0;
+ int field_num = 0;
line_no++;
- field = csv_lineparse(ibuf, "\t", "", line_no);
+ char* field = csv_lineparse(ibuf, "\t", "", line_no);
while (field) {
switch (field_num) {
continue;
}
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
if (stealth) {
if (!snmac) {
void
fix_netstumbler_dupes()
{
- int i, ct = waypt_count(), serial = 0;
- htable_t* htable, *bh;
+ int ct = waypt_count(), serial = 0;
unsigned long last_crc;
- htable = (htable_t*) xmalloc(ct * sizeof *htable);
- bh = htable;
+ htable_t* htable = (htable_t*) xmalloc(ct * sizeof *htable);
+ htable_t* bh = htable;
- i = 0;
+ int i = 0;
#if NEWQ
// Why, oh, why is this format running over the entire waypoint list and
// modifying it? This seems wrong.
* it as one waypoint.
*/
if (getposn) {
- Waypoint* wpt;
posn_status st;
nmea_rd_posn_init(fname);
- wpt = nmea_rd_posn(&st);
+ Waypoint* wpt = nmea_rd_posn(&st);
if (!wpt) {
return;
}
if (fields.size() > 8) hdop = fields[8].toDouble();
double alt = unknown_alt;
if (fields.size() > 9) alt = fields[9].toDouble();
- QChar altunits;
+ QChar altunits ='M';
if (fields.size() > 10) altunits = fields[10][0];
double geoidheight = unknown_alt;
if (fields.size() > 11) geoidheight = fields[11].toDouble();
ENQUEUE_HEAD(&pcmpt_head, &curr_waypt->Q);
} else {
queue* elem, *tmp;
- route_head* trk_head;
if (QUEUE_EMPTY(&pcmpt_head)) {
return;
* we can rip through the queue forward now to get our
* handy-dandy reversing effect.
*/
- trk_head = route_head_alloc();
+ route_head* trk_head = route_head_alloc();
track_add_head(trk_head);
QUEUE_FOR_EACH(&pcmpt_head, elem, tmp) {
Waypoint* wpt = (Waypoint*) dequeue(elem);
if (tm.tm_year == 0) {
queue* elem, *temp;
Waypoint* prev = nullptr;
- time_t delta_tm;
if (optdate == nullptr) {
warning(MYNAME ": No date found within track (all points dropped)!\n");
track_del_head(track);
return;
}
- delta_tm = mkgmtime(&opt_tm);
+ time_t delta_tm = mkgmtime(&opt_tm);
QUEUE_FOR_EACH(&track->waypoint_list, elem, temp) {
Waypoint* wpt = (Waypoint*)elem;
prev = wpt;
}
} else {
- time_t prev;
-
tm.tm_hour = 23; /* last date found */
tm.tm_min = 59;
tm.tm_sec = 59;
- prev = mkgmtime(&tm);
+ time_t prev = mkgmtime(&tm);
/* go backward through the track and complete timestamps */
Waypoint* wpt = (Waypoint*)elem;
if (wpt->wpt_flags.fmt_use != 0) {
- time_t dt;
-
wpt->wpt_flags.fmt_use = 0; /* reset flag */
- dt = (prev / SECONDS_PER_DAY) * SECONDS_PER_DAY;
+ time_t dt = (prev / SECONDS_PER_DAY) * SECONDS_PER_DAY;
wpt->creation_time += dt;
if (wpt->creation_time.toTime_t() > prev) {
wpt->creation_time+=SECONDS_PER_DAY;
static void
nmea_parse_one_line(char* ibuf)
{
- char* ck;
char* tbuf = lrtrim(ibuf);
/*
return;
}
- ck = strrchr(tbuf, '*');
+ char* ck = strrchr(tbuf, '*');
if (ck != nullptr) {
*ck = '\0';
int ckval = nmea_cksum(&tbuf[1]);
curr_waypt = nullptr;
while ((ibuf = gbfgetstr(file_in))) {
- char* sdatum, *cx;
-
line++;
if ((line == 0) & file_in->unicode) {
*/
/* Check the GPS datum */
- cx = strchr(&ibuf[12], '/');
+ char* cx = strchr(&ibuf[12], '/');
if (cx != nullptr) {
- char* edatum;
- sdatum = cx + 1;
- edatum = strchr(sdatum, '/');
+ char* sdatum = cx + 1;
+ char* edatum = strchr(sdatum, '/');
if (edatum) {
*edatum = 0;
}
char ibuf[1024];
for (brp = br; *brp > 0; brp++) {
- int rv;
if (global_opts.debug_level > 1) {
fprintf(stderr, "Trying %d\n", *brp);
}
gbser_set_speed(gbser_handle, *brp);
reset_sirf_to_nmea(*brp);
- rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf),
- 1000, 0x0a, 0x0d);
+ int rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf),
+ 1000, 0x0a, 0x0d);
/*
* If we didn't get a read error but did get a string that
* started with a dollar sign, we're probably in NMEA mode
*/
for (int i = 0; i < 10; i++) {
- int rv;
ibuf[0] = 0;
- rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf), 2000, 0x0a, 0x0d);
+ int rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf), 2000, 0x0a, 0x0d);
if (global_opts.debug_level > 1) {
safe_print(strlen(ibuf), ibuf);
}
nmea_wayptpr(const Waypoint* wpt)
{
char obuf[200];
- double lat,lon;
QString s;
- int cksum;
- lat = degrees2ddmm(wpt->latitude);
- lon = degrees2ddmm(wpt->longitude);
+ double lat = degrees2ddmm(wpt->latitude);
+ double lon = degrees2ddmm(wpt->longitude);
if (global_opts.synthesize_shortnames) {
s = mkshort_from_wpt(mkshort_handle, wpt);
} else {
fabs(lat), lat < 0 ? 'S' : 'N',
fabs(lon), lon < 0 ? 'W' : 'E', CSTRc(s)
);
- cksum = nmea_cksum(obuf);
+ int cksum = nmea_cksum(obuf);
gbfprintf(file_out, "$%s*%02X\n", obuf, cksum);
if (sleepus >= 0) {
gbfflush(file_out);
{
char obuf[200];
char fix='0';
- double lat,lon;
int cksum;
- struct tm* tm;
time_t hms;
time_t ymd;
last_time = wpt->GetCreationTime().toTime_t();
}
- lat = degrees2ddmm(wpt->latitude);
- lon = degrees2ddmm(wpt->longitude);
+ double lat = degrees2ddmm(wpt->latitude);
+ double lon = degrees2ddmm(wpt->longitude);
time_t ct = wpt->GetCreationTime().toTime_t();
- tm = gmtime(&ct);
+ struct tm* tm = gmtime(&ct);
if (tm) {
hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec;
ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year;
nmn4_read_data()
{
char* buff;
- char* str;
- QString c;
- int column;
int line = 0;
- QString zip1, zip2, city, street, number;
- route_head* route;
- Waypoint* wpt;
+ QString zip2, city, street, number;
- route = route_head_alloc();
+ route_head* route = route_head_alloc();
route_add_head(route);
while ((buff = gbfgetstr(fin))) {
if ((line++ == 0) && fin->unicode) {
cet_convert_init(CET_CHARSET_UTF8, 1);
}
- str = buff = lrtrim(buff);
+ char* str = buff = lrtrim(buff);
if (*buff == '\0') {
continue;
}
nmn4_check_line(buff);
/* for a quiet compiler */
- zip1 = zip2 = city = street = number = QString();
+ QString zip1 = zip2 = city = street = number = QString();
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
- column = -1;
- c = csv_lineparse(str, "|", "", column++);
+ int column = -1;
+ QString c = csv_lineparse(str, "|", "", column++);
while (c != nullptr) {
switch (column) {
case 0: /* "-" */ /* unknown fields for the moment */
osm_feature_symbol(const int ikey, const char* value)
{
char buff[128];
- QString key;
buff[0] = ikey;
strncpy(&buff[1], value, sizeof(buff) - 1);
- key = QString::fromUtf8(buff);
+ QString key = QString::fromUtf8(buff);
QString result;
if (values.contains(key)) {
osm_node_tag(xg_string, const QXmlStreamAttributes* attrv)
{
QString key, value;
- QString str;
signed char ikey;
if (attrv->hasAttribute("k")) {
value = attrv->value("v").toString();
}
- str = osm_strip_html(value);
+ QString str = osm_strip_html(value);
if (key == QLatin1String("name")) {
if (wpt->shortname.isEmpty()) {
osm_way_tag(xg_string, const QXmlStreamAttributes* attrv)
{
QString key, value;
- QString str;
signed char ikey;
if (attrv->hasAttribute("k")) {
value = attrv->value("v").toString();
}
- str = osm_strip_html(value);
+ QString str = osm_strip_html(value);
if (key == QLatin1String("name")) {
if (rte->rte_name.isEmpty()) {
static void
osm_write_opt_tag(const char* atag)
{
- char* tag, *cin, *ce;
+ char* cin;
if (!atag) {
return;
}
- tag = cin = xstrdup(atag);
- ce = cin + strlen(cin);
+ char* tag = cin = xstrdup(atag);
+ char* ce = cin + strlen(cin);
while (cin < ce) {
char* sc, *dp;
waypoints.insert(name, wpt);
- int* id;
-
- id = (int*) xmalloc(sizeof(*id));
+ int* id = (int*) xmalloc(sizeof(*id));
*id = --node_id;
(const_cast<Waypoint*>(wpt))->extra_data = id;
{
QString buff;
char* trk_name = nullptr;
- Waypoint* wpt_tmp;
- int i;
int linecount = 0;
while ((buff = gbfgetstr(file_in)), !buff.isNull()) {
if (buff.contains(',')) {
bool ozi_fsdata_used = false;
ozi_fsdata* fsdata = ozi_alloc_fsdata();
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
/* data delimited by commas, possibly enclosed in quotes. */
char* orig_s = xstrdup(CSTR(buff));
char* s = csv_lineparse(orig_s, ",", "", linecount);
- i = 0;
+ int i = 0;
bool header = false;
while (s) {
switch (ozi_objective) {
int utmz;
double utme, utmn;
char utmc;
- int valid, result, ct;
+ int result;
+ int ct;
double lx, ly;
const char* format;
- valid = 1;
+ int valid = 1;
switch (grid) {
char* buff;
route_head* track = nullptr;
route_head* route = nullptr;
- int points;
int line_number = 0;
read_as_degrees = 0;
- points = 0;
+ int points = 0;
// Each line is both |buff| as a C string and |line| as a QString.
while ((buff = gbfgetstr(file_in))) {
}
static void gpsutil_disp(const Waypoint* wpt) {
- double lon, lat;
int icon_token = 0;
- lon = degrees2ddmm(wpt->longitude);
- lat = degrees2ddmm(wpt->latitude);
+ double lon = degrees2ddmm(wpt->longitude);
+ double lat = degrees2ddmm(wpt->latitude);
QDateTime dt = wpt->GetCreationTime().toUTC();
const QString ds = dt.toString("dd-MMM-yy hh:mm:ss").toUpper();
}
static void pcx_track_disp(const Waypoint* wpt) {
- double lon, lat;
-
- lon = degrees2ddmm(wpt->longitude);
- lat = degrees2ddmm(wpt->latitude);
+ double lon = degrees2ddmm(wpt->longitude);
+ double lat = degrees2ddmm(wpt->latitude);
QDateTime dt = wpt->GetCreationTime().toUTC();
const QString ds = dt.toString("dd-MMM-yy hh:mm:ss").toUpper();
while (1 == gbfread(&bc, sizeof(bc), 1, file_in)) {
struct tm tm;
- Waypoint* wpt;
if (strcmp(bc.id, header_id) != 0) {
fatal(MYNAME ": invalid breadcrumb header in input file.\n");
tm.tm_min = le_readu16(&bc.minute);
tm.tm_sec = le_readu16(&bc.second);
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = le_read_float(&bc.latitude);
wpt->longitude = le_read_float(&bc.longitude);
wpt->altitude = FEET_TO_METERS(le_read_float(&bc.altitude));
pocketfms_waypt_disp(const Waypoint* wpt)
{
struct breadcrumb bc;
- struct tm* tm;
memset(&bc, 0, sizeof(bc));
const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = localtime(&tt);
+ struct tm* tm = localtime(&tt);
if (wpt->creation_time.isValid()) {
const time_t tt = wpt->GetCreationTime().toTime_t();
tm = gmtime(&tt);
char* buff;
int linecount = 0;
while ((buff = gbfgetstr(file_in))) {
- char* s;
- Waypoint* wpt;
rtrim(buff);
if (strlen(buff) == 0) {
break;
}
linecount++;
- wpt = new Waypoint;
- s = buff;
+ Waypoint* wpt = new Waypoint;
+ char* s = buff;
s = csv_lineparse(s, "\\w", "", linecount);
if (!s) {
fatal(MYNAME "Invalid name");
queue* elem, * tmp;
Waypoint* waypointp;
extra_data* ed;
- double lat1, lon1, lat2, lon2;
- double olat, olon;
int fileline = 0;
int first = 1;
int last = 0;
char* line;
- gbfile* file_in;
- file_in = gbfopen(polyfileopt, "r", MYNAME);
+ gbfile* file_in = gbfopen(polyfileopt, "r", MYNAME);
- olat = olon = lat1 = lon1 = lat2 = lon2 = BADVAL;
+ double olat = BADVAL;
+ double olon = BADVAL;
+ double lat1 = BADVAL;
+ double lon1 = BADVAL;
+ double lat2 = BADVAL;
+ double lon2 = BADVAL;
while ((line = gbfgetstr(file_in))) {
fileline++;
void PositionFilter::position_runqueue(queue* q, int nelems, int qtype)
{
queue* elem, * tmp;
- Waypoint** comp;
- int* qlist;
double dist, diff_time;
int i = 0, anyitem;
- comp = (Waypoint**) xcalloc(nelems, sizeof(*comp));
- qlist = (int*) xcalloc(nelems, sizeof(*qlist));
+ Waypoint** comp = (Waypoint**) xcalloc(nelems, sizeof(*comp));
+ int* qlist = (int*) xcalloc(nelems, sizeof(*qlist));
#if NEWQ
foreach (Waypoint* waypointp, waypt_list) {
static void
psit_waypoint_w(gbfile* psit_file, const Waypoint* wpt)
{
- int icon;
- const char* ident;
char* src = nullptr; /* BUGBUG Passed to mkshort */
gbfprintf(psit_file, "%11.6f,%11.6f,",
gbfprintf(psit_file, "%8.2f,",
wpt->altitude);
- ident = global_opts.synthesize_shortnames ?
- mkshort(mkshort_handle, src) :
- xstrdup(wpt->shortname);
+ const char* ident = global_opts.synthesize_shortnames ?
+ mkshort(mkshort_handle, src) :
+ xstrdup(wpt->shortname);
gbfprintf(psit_file, " %-6s, ", ident);
xfree(ident);
- icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX);
+ int icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX);
if (get_cache_icon(wpt) && wpt->icon_descr.compare(QLatin1String("Geocache Found")) != 0) {
icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), PCX);
psit_route_r(gbfile* psit_file, route_head** rte)
{
char rtename[256];
- route_head* rte_head;
psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), ltrimEOL);
rtrim(rtename);
- rte_head = route_head_alloc();
+ route_head* rte_head = route_head_alloc();
rte_head->rte_name = rtename;
route_add_head(rte_head);
*rte = rte_head;
psit_track_r(gbfile* psit_file, route_head**)
{
char trkname[256];
- unsigned int trk_num;
struct tm tmTime;
- Waypoint* thisWaypoint;
psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), ltrimEOL);
if (strlen(psit_current_token) == 0) {
rtrim(trkname);
- trk_num = 0;
+ unsigned int trk_num = 0;
route_head* track_head = nullptr;
psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), wscomma);
while (psit_isKnownToken(psit_current_token) != 0) {
if (strlen(psit_current_token) > 0) {
- thisWaypoint = new Waypoint;
+ Waypoint* thisWaypoint = new Waypoint;
thisWaypoint->latitude = atof(psit_current_token);
sortqueue(queue* qh, T cmp)
{
- queue* p, *q, *e, *tail, *oldhead, *list;
- int insize, nmerges, psize, qsize, i;
+ queue* e;
/*
* Special case: if `list' is empty, we're done.
* element. So remove the list head for now. Put it back later.
*/
- list = QUEUE_FIRST(qh);
+ queue* list = QUEUE_FIRST(qh);
dequeue(qh);
- insize = 1;
+ int insize = 1;
while (true) {
- p = list;
- oldhead = list; /* only used for circular linkage */
+ queue* p = list;
+ queue* oldhead = list; /* only used for circular linkage */
list = nullptr;
- tail = nullptr;
+ queue* tail = nullptr;
- nmerges = 0; /* count number of merges we do in this pass */
+ int nmerges = 0; /* count number of merges we do in this pass */
while (p) {
nmerges++; /* there exists a merge to be done */
/* step `insize' places along from p */
- q = p;
- psize = 0;
- for (i = 0; i < insize; i++) {
+ queue* q = p;
+ int psize = 0;
+ for (int i = 0; i < insize; i++) {
psize++;
q = (q->next == oldhead ? nullptr : q->next);
if (!q) {
/* if q hasn't fallen off end, we have
* two lists to merge */
- qsize = insize;
+ int qsize = insize;
/* now we have two lists; merge them */
while (psize > 0 || (qsize > 0 && q)) {
static char*
rand_str(const int maxlen, const char* fmt)
{
- char* res;
- int len;
+ int len = rand_int(maxlen) + 1;
- len = rand_int(maxlen) + 1;
-
- res = (char*) xmalloc(len + 1);
+ char* res = (char*) xmalloc(len + 1);
res[len] = '\0';
for (int i = 0; i < len; i++) {
{
#define RND(a) (rand_int(a) > 0)
- int points;
route_head* head;
Waypoint* prev = nullptr;
time_t time = gpsbabel_time;
}
- points = (opt_points) ? atoi(opt_points) : rand_int(128) + 1;
+ int points = (opt_points) ? atoi(opt_points) : rand_int(128) + 1;
if (doing_trks || doing_rtes) {
head = route_head_alloc();
if (doing_trks) {
}
for (int i = 0; i < points; i++) {
-
- Waypoint* wpt;
- garmin_fs_t* gmsd;
-
- wpt = new Waypoint;
- gmsd = garmin_fs_alloc(-1);
+ Waypoint* wpt = new Waypoint;
+ garmin_fs_t* gmsd = garmin_fs_alloc(-1);
fs_chain_add(&wpt->fs, (format_specific_data*) gmsd);
do {
find_symbol_num(const QString& descr)
{
if (!descr.isNull()) {
-
- raymarine_symbol_mapping_t* a;
-
- a = &raymarine_symbols[0];
+ raymarine_symbol_mapping_t* a = &raymarine_symbols[0];
for (unsigned int i = 0; i < RAYMARINE_SYMBOL_CT; i++, a++) {
if (descr.compare(a->name, Qt::CaseInsensitive) == 0) {
static void
raymarine_read()
{
- Waypoint* wpt;
-
/* Read all waypoints */
for (unsigned int ix = 0; ix < 0x3FFF; ix++) {
break;
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->shortname = name;
wpt->latitude = atof(lat);
wpt->longitude = atof(lon);
for (unsigned int rx = 0; rx < 0x3FFF; rx++) {
char sect[10];
char* name;
- route_head* rte;
snprintf(sect, sizeof(sect), "Rt%d", rx);
if (nullptr == (name = inifile_readstr(fin, sect, "Name"))) {
break;
}
- rte = route_head_alloc();
+ route_head* rte = route_head_alloc();
rte->rte_name = name;
route_add_head(rte);
for (int wx = 0; wx < 0x3FFF; wx++) {
char buff[32];
- char* str;
- Waypoint* wpt;
snprintf(buff, sizeof(buff), "Mk%d", wx);
- str = inifile_readstr(fin, sect, buff);
+ char* str = inifile_readstr(fin, sect, buff);
if ((str == nullptr) || (*str == '\0')) {
break;
}
- wpt = find_waypt_by_name(str);
+ Waypoint* wpt = find_waypt_by_name(str);
if (wpt == nullptr)
fatal(MYNAME ": No associated waypoint for route point %s (Route %s)!\n",
str, qPrintable(rte->rte_name));
static void
write_waypoint(gbfile* fout, const Waypoint* wpt, const int waypt_no, const char* location)
{
- QString notes;
- char* name;
- double time;
-
- notes = wpt->notes;
+ QString notes = wpt->notes;
if (notes == nullptr) {
notes = wpt->description;
if (notes == nullptr) {
}
}
notes = csv_stringclean(notes, LINE_FEED);
- time = wpt->creation_time.isValid() ? TIMET_TO_EXCEL(wpt->GetCreationTime().toTime_t()) : TIMET_TO_EXCEL(gpsbabel_time);
- name = (char*)wpt->extra_data;
+ double time = wpt->creation_time.isValid() ? TIMET_TO_EXCEL(wpt->GetCreationTime().toTime_t()) : TIMET_TO_EXCEL(gpsbabel_time);
+ char* name = (char*)wpt->extra_data;
gbfprintf(fout, "[Wp%d]" LINE_FEED
"Loc=%s" LINE_FEED
static void
write_route_head_cb(const route_head* rte)
{
- QString name;
-
- name = rte->rte_name;
+ QString name = rte->rte_name;
if (name.isEmpty()) {
name=QString("Route%1").arg(rte_index);
}
static short_handle
raymarine_new_short_handle()
{
- short_handle res;
-
- res = mkshort_new_handle();
+ short_handle res = mkshort_new_handle();
setshort_length(res, 16);
setshort_badchars(res, ",");
raymarine_write()
{
int i;
- Waypoint* wpt;
waypt_table_sz = 0;
waypt_table_ct = 0;
/* release local used data */
for (i = 0; i < waypt_table_ct; i++) {
- wpt = waypt_table[i];
+ Waypoint* wpt = waypt_table[i];
xfree(wpt->extra_data);
wpt->extra_data = nullptr;
}
/* Cast away const-ness */
Waypoint* wpp = const_cast<Waypoint*>(waypointp);
- int curr_new_trkseg;
-
- curr_new_trkseg = waypointp->wpt_flags.new_trkseg;
+ int curr_new_trkseg = waypointp->wpt_flags.new_trkseg;
wpp->wpt_flags.new_trkseg = prev_new_trkseg;
prev_new_trkseg = curr_new_trkseg;
}
int
color_to_bbggrr(const char* opt_color)
{
- int color_num;
char* ep;
- color_num = strtol(opt_color, &ep, 10);
+ int color_num = strtol(opt_color, &ep, 10);
if (ep != opt_color) {
return color_num;
common_route_by_name(queue* routes, const char* name)
{
queue* elem, *tmp;
- route_head* rte;
QUEUE_FOR_EACH(routes, elem, tmp) {
- rte = (route_head*) elem;
+ route_head* rte = (route_head*) elem;
if (rte->rte_name == name) {
return rte;
}
{
queue* elem, *tmp;
QUEUE_FOR_EACH(qh, elem, tmp) {
- const route_head* rhp;
- rhp = (route_head*) elem;
+ const route_head* rhp = (route_head*) elem;
if (rhp->session == se) {
if (rh) {
(*rh)(rhp);
route_flush_q(queue* head)
{
queue* elem, *tmp;
- queue* q;
QUEUE_FOR_EACH(head, elem, tmp) {
- q = dequeue(elem);
+ queue* q = dequeue(elem);
any_route_free((route_head*) q);
}
}
route_flush(queue* head)
{
queue* elem, *tmp;
- queue* q;
QUEUE_FOR_EACH(head, elem, tmp) {
- q = dequeue(elem);
+ queue* q = dequeue(elem);
any_route_free((route_head*)q);
}
}
route_copy(int* dst_count, int* dst_wpt_count, queue** dst, queue* src)
{
queue* elem, *tmp, *elem2, *tmp2;
- route_head* rte_new;
int junk;
if (!dst_wpt_count) {
dst_wpt_count = &junk;
QUEUE_FOR_EACH(src, elem, tmp) {
route_head* rte_old = (route_head*)elem;
- rte_new = route_head_alloc();
+ route_head* rte_new = route_head_alloc();
rte_new->rte_name = rte_old->rte_name;
rte_new->rte_desc = rte_old->rte_desc;
rte_new->rte_url = rte_old->rte_url;
void track_recompute(const route_head* trk, computed_trkdata** trkdatap)
{
Waypoint first;
- Waypoint* thisw;
Waypoint* prev = &first;
queue* elem, *tmp;
int tkpt = 0;
tdata->max_alt = unknown_alt;
QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) {
- double tlat, tlon, plat, plon, dist;
-
- thisw = (Waypoint*)elem;
+ Waypoint* thisw = (Waypoint*)elem;
/*
* gcdist and heading want radians, not degrees.
*/
- tlat = RAD(thisw->latitude);
- tlon = RAD(thisw->longitude);
- plat = RAD(prev->latitude);
- plon = RAD(prev->longitude);
+ double tlat = RAD(thisw->latitude);
+ double tlon = RAD(thisw->longitude);
+ double plat = RAD(prev->latitude);
+ double plon = RAD(prev->longitude);
WAYPT_SET(thisw, course, heading_true_degrees(plat, plon,
tlat, tlon));
- dist = radtometers(gcdist(plat, plon, tlat, tlon));
+ double dist = radtometers(gcdist(plat, plon, tlat, tlon));
/*
* Avoid that 6300 mile jump as we move from 0,0.
static void
my_read()
{
-
- uint16_t version;
- uint32_t count;
- uint32_t outercount;
- uint32_t recsize;
- uint16_t stringlen;
- unsigned char* record;
static int serial = 0;
struct ll {
int32_t lat;
int32_t lon;
} *latlon;
struct ll mylatlon;
- uint16_t coordcount;
route_head* track_head = nullptr;
Waypoint* wpt_tmp;
char* routename = nullptr;
double oldlon = 0;
ReadShort(infile); /* magic */
- version = ReadShort(infile);
+ uint16_t version = ReadShort(infile);
ReadLong(infile);
if (version >= 6) {
*/
ReadShort(infile);
- recsize = ReadLong(infile);
+ uint32_t recsize = ReadLong(infile);
/*
* the first recsize, oddly, doesn't include the filename string
* but it does include the header.
*/
- record = ReadRecord(infile, recsize);
+ unsigned char* record = ReadRecord(infile, recsize);
- stringlen = le_read16((uint16_t*)(record + 0x1a));
+ uint16_t stringlen = le_read16((uint16_t*)(record + 0x1a));
if (stringlen) {
routename = (char*)xmalloc(stringlen + 1);
routename[stringlen] = '\0';
track_head->rte_name = routename;
}
}
- count = ReadLong(infile);
+ uint32_t count = ReadLong(infile);
while (count) {
ReadShort(infile);
recsize = ReadLong(infile);
if (version < 6 || control) {
- double lat;
- double lon;
-
record = ReadRecord(infile, recsize);
latlon = (struct ll*)(record);
/* These records are backwards for some reason */
- lat = (0x80000000UL -
- le_read32(&latlon->lon)) / (double)(0x800000);
- lon = (0x80000000UL -
- le_read32(&latlon->lat)) / (double)(0x800000);
+ double lat = (0x80000000UL -
+ le_read32(&latlon->lon)) / (double)(0x800000);
+ double lon = (0x80000000UL -
+ le_read32(&latlon->lat)) / (double)(0x800000);
wpt_tmp = new Waypoint;
wpt_tmp->latitude = lat;
wpt_tmp->longitude = -lon;
if (control) {
- int obase, addrlen, cmtlen;
+ int obase;
/* Somewhere around TopoUSA 6.0, these moved */
/* This block also seems to get miscompiled
obase = 18;
}
- addrlen = le_read16(&record[obase]);
- cmtlen = le_read16(&record[obase+2+addrlen]);
+ int addrlen = le_read16(&record[obase]);
+ int cmtlen = le_read16(&record[obase+2+addrlen]);
(void) cmtlen;
#if NEW_STRINGS
// That we've had no bugreports on this strongly indicates this code
* outercount is the number of route segments (start+end+stops+vias-1)
*/
- outercount = ReadLong(infile);
+ uint32_t outercount = ReadLong(infile);
while (outercount) {
/*
seglen /= 5280*12*2.54/100000; /* to miles */
}
- coordcount = le_read16((uint16_t*)
- (record + 2 + stringlen + 0x3c));
+ uint16_t coordcount = le_read16((uint16_t*)
+ (record + 2 + stringlen + 0x3c));
latlon = (struct ll*)(record + 2 + stringlen + 0x3c + 2);
count--;
if (count) {
int first = 1;
while (coordcount) {
- double lat;
- double lon;
-
wpt_tmp = new Waypoint;
// copy to make sure we don't violate alignment restrictions.
memcpy(&mylatlon,latlon,sizeof(mylatlon));
- lat = (0x80000000UL -
- le_read32(&mylatlon.lat)) /
- (double)(0x800000);
- lon = (0x80000000UL -
- le_read32(&mylatlon.lon)) /
- (double)(0x800000);
+ double lat = (0x80000000UL -
+ le_read32(&mylatlon.lat)) /
+ (double)(0x800000);
+ double lon = (0x80000000UL -
+ le_read32(&mylatlon.lon)) /
+ (double)(0x800000);
wpt_tmp->latitude = lat;
wpt_tmp->longitude = -lon;
static size_t
read_packet(int* type, void* payload, size_t max_len)
{
- size_t size, data_size;
unsigned char start[4];
- unsigned int checksum_exp, checksum_act;
- unsigned char* data;
if (gbfread(start, sizeof(start), 1, file_handle) != 1) {
if (gbfeof(file_handle)) {
fatal(MYNAME ": Format error: Bad packet start.\n");
}
- size = be_readu16(start + 2);
+ size_t size = be_readu16(start + 2);
if (size < 1 || max_len < size) {
fatal(MYNAME ": Format error: unexpected size: %d.\n", (int) size);
}
/* allocate space for checksum and trailing 0xb0b3 */
- data_size = size + 4;
+ size_t data_size = size + 4;
/* data_size can be up to about 64k */
- data = (unsigned char*) xmalloc(data_size);
+ unsigned char* data = (unsigned char*) xmalloc(data_size);
if (gbfread(data, data_size, 1, file_handle) != 1) {
fatal(MYNAME ": Format error: could not read %d bytes.\n",
*type = data[0];
- checksum_exp = be_readu16(data + size);
- checksum_act = navilink_checksum_packet(data, size);
+ unsigned int checksum_exp = be_readu16(data + size);
+ unsigned int checksum_act = navilink_checksum_packet(data, size);
if (checksum_exp != checksum_act) {
fatal(MYNAME ": Checksum error - expected %x got %x\n",
read_sbn_header(route_head*)
{
char header[QRY_INFORMATION_LEN];
- size_t len;
int type = 0;
- len = read_packet(&type, header, sizeof(header));
+ size_t len = read_packet(&type, header, sizeof(header));
if (len == 0 || type != PID_QRY_INFORMATION ||
!locosys_decode_file_id(header, len)) {
sbn_read()
{
if (global_opts.masked_objective & TRKDATAMASK) {
- route_head* track;
-
- track = route_head_alloc();
+ route_head* track = route_head_alloc();
track_add_head(track);
read_sbn_header(track);
sbp_read()
{
Waypoint* logpoint;
- route_head* track;
- track = route_head_alloc();
+ route_head* track = route_head_alloc();
track_add_head(track);
read_sbp_header(track);
void
start_session(const char* name, const char* filename)
{
- session_t* s;
-
if (session_ct == 0) {
QUEUE_INIT(&session_list);
}
session_ct++;
- s = (session_t*) xcalloc(1, sizeof(*s));
+ session_t* s = (session_t*) xcalloc(1, sizeof(*s));
ENQUEUE_TAIL(&session_list, &s->Q);
QUEUE_INIT(&s->category_list);
s->nr = session_ct;
SHPGetInfo(ihandle, &npts, nullptr, nullptr, nullptr);
for (int iShape=0; iShape<npts; iShape++) {
- SHPObject* shp;
Waypoint* wpt;
QString name;
QString url;
- shp = SHPReadObject(ihandle, iShape);
+ SHPObject* shp = SHPReadObject(ihandle, iShape);
if (nameidx >= 0) {
name = DBFReadStringAttribute(ihandledb, iShape, nameidx);
// } else if (nameidx == -1) {
static void
my_write_wpt(const Waypoint* wpt)
{
- SHPObject* shpobject;
-
// note that the z coordinate (&wpt->altitude) does not apply
// to SHPT_POINT.
// We could potentially write SHPT_POINTZ, but we would have
// to address what to do when we don't have altitude data.
- shpobject = SHPCreateSimpleObject(SHPT_POINT, 1,
- &wpt->longitude,
- &wpt->latitude,
- &wpt->altitude);
+ SHPObject* shpobject = SHPCreateSimpleObject(SHPT_POINT, 1,
+ &wpt->longitude,
+ &wpt->latitude,
+ &wpt->altitude);
int iShape = SHPWriteObject(ohandle, -1, shpobject);
SHPDestroyObject(shpobject);
DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx,
static void
poly_deinit(const route_head* rte)
{
- SHPObject* shpobject;
// note that the z coordinate (polybufz) does not apply
// to SHPT_ARC.
// We could potentially write SHPT_ARCZ, but we would have
// to address what to do when we don't have altitude data.
- shpobject = SHPCreateSimpleObject(SHPT_ARC, poly_count,
- polybufx, polybufy, polybufz);
+ SHPObject* shpobject = SHPCreateSimpleObject(SHPT_ARC, poly_count,
+ polybufx, polybufy, polybufz);
int iShape = SHPWriteObject(ohandle, -1, shpobject);
SHPDestroyObject(shpobject);
DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx,
static Waypoint*
skyforce_parse_coords(const char* str)
{
- Waypoint* wpt;
-
if (strlen(str) < 38) {
fatal(MYNAME ": Incomplete line!\n");
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = atof(str + 21);
if (str[20] == 'S') {
static Waypoint*
skyforce_parse_wpt(const char* str, int* rte_num)
{
- Waypoint* wpt;
-
- wpt = skyforce_parse_coords(str);
+ Waypoint* wpt = skyforce_parse_coords(str);
if (wpt == nullptr) {
return nullptr;
}
skyforce_parse_trk(const char* str)
{
char buf[15];
- int len;
-
- Waypoint* wpt;
- wpt = skyforce_parse_coords(str);
+ Waypoint* wpt = skyforce_parse_coords(str);
if (wpt == nullptr) {
return nullptr;
}
dt = dt.addYears(100);
wpt->SetCreationTime(dt);
- len = strlen(str);
+ int len = strlen(str);
if (len >= 45) {
WAYPT_SET(wpt, speed, KNOTS_TO_MPS(atof(str + 39)));
skyforce_waypt_disp_cb(const Waypoint* wpt)
{
char buf[75]; /* long enough for all data types */
- double lat, lon;
memset(buf, ' ', sizeof(buf));
}
- lat = degrees2ddmm(wpt->latitude);
+ double lat = degrees2ddmm(wpt->latitude);
buf[20] = (wpt->latitude < 0) ? 'S' : 'N';
snprintf(&buf[21], sizeof(buf) - 21, "%06.2f ", fabs(lat));
- lon = degrees2ddmm(wpt->longitude);
+ double lon = degrees2ddmm(wpt->longitude);
buf[29] = (wpt->longitude < 0) ? 'W' : 'E';
snprintf(&buf[30], sizeof(buf) - 30, "%08.2f ", fabs(lon));
if (global_opts.objective == trkdata) {
- double alt, speed;
+ double alt;
if (wpt->altitude == unknown_alt) {
alt = 0;
} else {
alt = METERS_TO_FEET(wpt->altitude);
}
- speed = MPS_TO_KNOTS(waypt_speed(prev_wpt, wpt));
+ double speed = MPS_TO_KNOTS(waypt_speed(prev_wpt, wpt));
snprintf(&buf[39], sizeof(buf) - 39, "%06.2f 000.00 %c%05d",
speed,
skyforce_read()
{
char* str;
- route_head* rte, *trk;
wpt_num = 0;
- rte = trk = nullptr;
+ route_head* rte = nullptr;
+ route_head* trk = nullptr;
rte_num = -1;
while ((str = gbfgetstr(fin))) {
static int
rd_buf(const uint8_t* buf, int len)
{
- int rc, timeout;
char dump[16*3+16+2];
/* Allow TIMEOUT plus the time needed to actually receive the data bytes:
* baudrate/10 bytes per second (8 data bits, start and stop bit)
* TODO: use dlbaud if selected.
*/
- timeout = TIMEOUT + len;//*1000/(skytraq_baud/10);
+ int timeout = TIMEOUT + len;//*1000/(skytraq_baud/10);
/*TODO: timeout gets <0 e.g. when len~=250000 --> 32bit signed int is too small.
if (skytraq_baud > 0) timeout = TIMEOUT + (long long int)len*1000*10/(long long int)skytraq_baud;
printf("len=%i skytraq_baud=%i timeout=%i\n", len, skytraq_baud, timeout);*/
- rc = gbser_read_wait(serial_handle, (void*)buf, len, timeout);
+ int rc = gbser_read_wait(serial_handle, (void*)buf, len, timeout);
if (rc < 0) {
db(1, MYNAME ": rd_buf(): Read error (%d)\n", rc);
return res_ERROR;
int errors = 5; /* allow this many errors */
unsigned int c, i, state;
signed int rcv_len;
- unsigned int calc_cs, rcv_cs;
for (i = 0, state = 0; i < RETRIES && state < sizeof(MSG_START); i++) {
c = rd_char(&errors);
db(2, "Receiving message with %i bytes of payload (expected >=%i)\n", rcv_len, len);
rd_buf((const unsigned char*) payload, MIN(rcv_len, len));
- calc_cs = skytraq_calc_checksum((const unsigned char*) payload, MIN(rcv_len, len));
+ unsigned int calc_cs = skytraq_calc_checksum((const unsigned char*) payload, MIN(rcv_len, len));
for (i = 0; i < rcv_len-len; i++) {
c = rd_char(&errors);
calc_cs ^= c;
}
- rcv_cs = rd_char(&errors);
+ unsigned int rcv_cs = rd_char(&errors);
if (rcv_cs != calc_cs) {
fatal(MYNAME ": Checksum error: got 0x%02x, expected 0x%02x\n", rcv_cs, calc_cs);
}
static void
skytraq_wr_msg(const uint8_t* payload, int len)
{
- int cs;
-
rd_drain();
wr_buf(MSG_START, sizeof(MSG_START));
wr_char(len & 0x0FF);
wr_buf(payload, len);
- cs = skytraq_calc_checksum(payload, len);
+ int cs = skytraq_calc_checksum(payload, len);
wr_char(cs);
wr_buf(NL, sizeof(NL));
}
static int
skytraq_wr_msg_verify(const uint8_t* payload, int len)
{
- int rc;
-
for (int i = 0; i < MSG_RETRIES; i++) {
if (i > 0) {
db(1, "resending msg (id=0x%02x)...\n", payload[0]);
}
skytraq_wr_msg(payload, len);
- rc = skytraq_expect_ack(payload[0]);
+ int rc = skytraq_expect_ack(payload[0]);
if (rc == res_OK || rc == res_NACK) {
return rc;
}
*/
uint8_t MSG_CONFIGURE_SERIAL_PORT[4]
= { 0x05, 0x00, 0x00, 0x02 };
- int rc;
db(2, "Setting baud rate to %i\n", baud);
fatal(MYNAME ": Unsupported baud rate: %ibd\n", baud);
}
- rc = skytraq_wr_msg_verify(MSG_CONFIGURE_SERIAL_PORT, sizeof(MSG_CONFIGURE_SERIAL_PORT));
+ int rc = skytraq_wr_msg_verify(MSG_CONFIGURE_SERIAL_PORT, sizeof(MSG_CONFIGURE_SERIAL_PORT));
if (rc != res_OK) {
db(2, "Warning: error setting skytraq device baud rate\n");
return rc;
*sectors_free = le_readu16(&MSG_LOG_STATUS_OUTPUT.sectors_free);
*sectors_total = le_readu16(&MSG_LOG_STATUS_OUTPUT.sectors_total);
- // print logging parameters -- useful, but does this belong here?
- unsigned int tmax, tmin, dmax, dmin, vmax, vmin;
// unsigned char log_bool, fifo_mode;
char* mystatus;
- tmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_time);
- tmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_time);
- dmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_dist);
- dmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_dist);
- vmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_speed);
- vmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_speed);
+ unsigned int tmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_time);
+ unsigned int tmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_time);
+ unsigned int dmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_dist);
+ unsigned int dmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_dist);
+ unsigned int vmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_speed);
+ unsigned int vmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_speed);
// log_bool = *(MSG_LOG_STATUS_OUTPUT.datalog_enable);
// fifo_mode = *(MSG_LOG_STATUS_OUTPUT.log_fifo_mode);
xasprintf(&mystatus, "#logging: tmin=%u, tmax=%u, dmin=%u, dmax=%u, vmin=%u, vmax=%u\n", tmin, tmax, dmin, dmax, vmin, vmax);
static void
state_init(struct read_state* pst)
{
- route_head* track;
-
- track = route_head_alloc();
+ route_head* track = route_head_alloc();
track->rte_name = "SkyTraq tracklog";
track->rte_desc = "SkyTraq GPS tracklog data";
track_add_head(track);
process_data_item(struct read_state* pst, const item_frame* pitem, int len)
{
int res = 0;
- double lat, lon, alt, spe;
+ double lat;
+ double lon;
+ double alt;
+ double spe;
unsigned int ts;
int poi = 0;
full_item f;
skytraq_read_multiple_sectors(int first_sector, unsigned int sector_count, uint8_t* buf)
{
uint8_t MSG_LOG_READ_MULTI_SECTORS[5] = { 0x1D };
- uint8_t* buf_end_tag;
- unsigned int cs, i, read_result;
+ unsigned int i;
if (first_sector < 0 || first_sector > 0xFFFF) {
fatal(MYNAME ": Invalid sector number (%i)\n", first_sector);
db(2, "Reading %i sectors beginning from #%i...\n", sector_count, first_sector);
- read_result = skytraq_wr_msg_verify((uint8_t*)&MSG_LOG_READ_MULTI_SECTORS, sizeof(MSG_LOG_READ_MULTI_SECTORS));
+ unsigned int read_result = skytraq_wr_msg_verify((uint8_t*)&MSG_LOG_READ_MULTI_SECTORS, sizeof(MSG_LOG_READ_MULTI_SECTORS));
if (read_result != res_OK) {
return read_result;
}
}
rd_buf(buf+SECTOR_SIZE*sector_count, sizeof(SECTOR_READ_END)+6);
- buf_end_tag = buf + SECTOR_SIZE*sector_count;
+ uint8_t* buf_end_tag = buf + SECTOR_SIZE*sector_count;
for (i = 0; i < sizeof(SECTOR_READ_END); i++) {
if (buf_end_tag[i] != SECTOR_READ_END[i]) {
db(1, MYNAME ": Wrong end tag: got 0x%02x ('%c'), expected 0x%02x ('%c')\n",
}
}
- cs = skytraq_calc_checksum(buf, SECTOR_SIZE*sector_count);
+ unsigned int cs = skytraq_calc_checksum(buf, SECTOR_SIZE*sector_count);
if (cs != buf_end_tag[sizeof(SECTOR_READ_END)]) {
db(1, MYNAME ": Checksum error while reading sector: got 0x%02x, expected 0x%02x\n",
buf_end_tag[sizeof(SECTOR_READ_END)], cs);
static void
skytraq_read()
{
- int dlbaud;
-
if (opt_set_location) {
skytraq_set_location();
return;
return;
}
- dlbaud = atoi(opt_dlbaud);
+ int dlbaud = atoi(opt_dlbaud);
if (dlbaud != 0 && dlbaud != skytraq_baud) {
skytraq_set_baud(dlbaud);
}
file_read()
{
struct read_state st;
- int rc, got_bytes;
+ int got_bytes;
int opt_first_sector_val = atoi(opt_first_sector);
int opt_last_sector_val = atoi(opt_last_sector);
- int sectors_read;
- uint8_t* buffer;
state_init(&st);
- buffer = (uint8_t*) xmalloc(SECTOR_SIZE);
+ uint8_t* buffer = (uint8_t*) xmalloc(SECTOR_SIZE);
if (opt_first_sector_val > 0) {
db(4, MYNAME ": Seeking to first-sector index %i\n", opt_first_sector_val*SECTOR_SIZE);
}
db(1, MYNAME ": Reading log data from file...\n");
- sectors_read = 0;
+ int sectors_read = 0;
while ((got_bytes = gbfread(buffer, 1, SECTOR_SIZE, file_handle)) > 0) {
db(4, MYNAME ": Decoding sector #%i...\n", sectors_read++);
- rc = process_data_sector(&st, buffer, got_bytes);
+ int rc = process_data_sector(&st, buffer, got_bytes);
if (opt_last_sector_val < 0) {
if (rc < (4096-FULL_ITEM_LEN)) {
db(1, MYNAME ": Empty sector encountered, terminating.\n");
// http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf
static void lla2ecef(double lat, double lng, double alt, double* ecef_x, double* ecef_y, double* ecef_z)
{
- long double n;
long double a = 6378137.0;
long double esqr = 6.69437999014e-3;
- long double s;
- long double llat, llng, lalt;
- llat=lat*M_PI/180;
- llng=lng*M_PI/180;
- lalt=alt;
+ long double llat = lat*M_PI/180;
+ long double llng = lng*M_PI/180;
+ long double lalt = alt;
- s=sin(llat);
- n = a / sqrt(1 - esqr * s*s);
+ long double s = sin(llat);
+ long double n = a / sqrt(1 - esqr * s*s);
*ecef_x = (double)((n+lalt) * cos(llat) * cos(llng));
*ecef_y = (double)((n+lalt) * cos(llat) * sin(llng));
uint8_t MSG_GET_POI[3] = { 0x4D, 0, 0};
uint8_t buf[32];
double lat, lng, alt;
- double ecef_x, ecef_y, ecef_z;
- Waypoint* wpt;
for (unsigned int poi = 0; poi<NUMPOI; poi++) {
MSG_GET_POI[1]=(poi>>8)&0xff;
warning(MYNAME ": cannot read poi %d '%s'\n", poi, poinames[poi]);
}
skytraq_rd_msg(buf, 25);
- ecef_x=be_read_double(buf+1);
- ecef_y=be_read_double(buf+9);
- ecef_z=be_read_double(buf+17);
+ double ecef_x = be_read_double(buf+1);
+ double ecef_y = be_read_double(buf+9);
+ double ecef_z = be_read_double(buf+17);
// todo - how to determine not-set POIs ?
if (ecef_x < 100.0 && ecef_y < 100.0 && ecef_z < 100.0) {
} else {
ECEF_to_LLA(ecef_x, ecef_y, ecef_z, &lat, &lng, &alt);
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->shortname = QString().sprintf("POI_%s", poinames[poi]);
wpt->description = QString().sprintf("miniHomer points to this coordinates if the %s symbol is on", poinames[poi]);
wpt->latitude = lat;
0, 0, 0, 0, 0, 0, 0, 0, //alt (double ecef)
0 // attr (u8, 1-> to flash, 0->ro sram)
};
- int n, result;
double lat, lng, alt;
double ecef_x, ecef_y, ecef_z;
- result=0; // result will be 0 if opt_poi isn't set
+ int result = 0; // result will be 0 if opt_poi isn't set
if (opt_poi) { // first check opt_poi
if (*opt_poi) {
lat=lng=alt=0.0;
* parse format of <lat>:<lng>[:alt]
* we assume at least two elements in the value string
*/
- n = sscanf(opt_poi, "%lf:%lf:%lf", &lat, &lng, &alt);
+ int n = sscanf(opt_poi, "%lf:%lf:%lf", &lat, &lng, &alt);
if (n >= 2) {
db(3, "found %d elems '%s':poi=%s@%d, lat=%f, lng=%f, alt=%f over=%s\n", n, opt_poi, poinames[poinum], poinum, lat, lng, alt);
lla2ecef(lat, lng, alt, &ecef_x, &ecef_y, &ecef_z);
void SimplifyRouteFilter::compute_xte(struct xte* xte_rec)
{
const Waypoint* wpt3 = xte_rec->intermed->wpt;
- double frac, reslat, reslon;
+ double reslat, reslon;
/* if no previous, this is an endpoint and must be preserved. */
if (!xte_rec->intermed->prev) {
xte_rec->distance = HUGEVAL;
}
// if timestamps exist, distance to interpolated point
if (wpt1->GetCreationTime() != wpt2->GetCreationTime()) {
- frac = (double)(wpt3->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t()) /
- (wpt2->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t());
+ double frac = (double)(wpt3->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t()) /
+ (wpt2->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t());
linepart(wpt1->latitude, wpt1->longitude,
wpt2->latitude, wpt2->longitude,
frac, &reslat, &reslon);
queue* elem = nullptr;
queue* tmp = nullptr;
queue tmp_queue;
- unsigned int tmp_count;
if (opt_push) {
tmp_elt = (struct stack_elt*)xmalloc(sizeof(struct stack_elt));
xfree(tmp);
track_restore(&tmp_queue);
- tmp_count = waypt_count();
+ unsigned int tmp_count = waypt_count();
set_waypt_count(tmp_elt->waypt_ct);
tmp_elt->waypt_ct = tmp_count;
}
static void
finalize_tracks(void)
{
- Waypoint** list;
queue* elem, *tmp;
- int index;
route_head* track = nullptr;
int trackno = 0;
return;
}
- list = (Waypoint**)xmalloc(count * sizeof(*list));
+ Waypoint** list = (Waypoint**)xmalloc(count * sizeof(*list));
- index = 0;
+ int index = 0;
QUEUE_FOR_EACH(&trackpts, elem, tmp) {
list[index] = (Waypoint*)elem;
dequeue(elem);
double* asc, double* desc)
{
if (trkpt_out != nullptr) {
-
- time_t time;
-
*course = heading_true_degrees(
RAD(trkpt_out->latitude), RAD(trkpt_out->longitude),
RAD(wpt->latitude), RAD(wpt->longitude));
*dist = 0; /* calc. diffs on 32- and 64-bit hosts */
}
- time = wpt->creation_time.toTime_t() - trkpt_out->GetCreationTime().toTime_t();
+ time_t time = wpt->creation_time.toTime_t() - trkpt_out->GetCreationTime().toTime_t();
if (time == 0) {
*speed = 0;
} else {
static void
stmwpp_data_read(void)
{
- char* buff;
int line = 0;
what = STM_NOTHING;
- buff = gbfgetstr(fin);
+ char* buff = gbfgetstr(fin);
buff = (buff == nullptr) ? (char*) "" : buff;
if (case_ignore_strncmp(buff, "Datum,WGS 84,WGS 84,", 20) != 0) {
stmwpp_write_double(const double val)
{
char buff[64];
- char* c;
- c = buff + snprintf(buff, sizeof(buff), "%3.7f", val);
+ char* c = buff + snprintf(buff, sizeof(buff), "%3.7f", val);
while (*--c == '0') {
*c = '\0';
}
stmwpp_waypt_cb(const Waypoint* wpt)
{
char cdate[16], ctime[16];
- struct tm tm;
if (track_index != track_num) {
return;
}
const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = *gmtime(&tt);
+ struct tm tm = *gmtime(&tt);
tm.tm_year += 1900;
tm.tm_mon++;
static void
subrip_prevwp_pr(const Waypoint* waypointp)
{
- QDateTime startdtime, enddtime;
- QTime starttime, endtime;
+ QDateTime enddtime;
/* Now that we have the next waypoint, we can write out the subtitle for
* the previous one.
gbfprintf(fout, "%d\n", stnum++);
/* Writes start and end time for subtitle display to file. */
- startdtime = prevwpp->GetCreationTime().addSecs(-time_offset);
+ QDateTime startdtime = prevwpp->GetCreationTime().addSecs(-time_offset);
if (!waypointp) {
enddtime = startdtime.addSecs(1);
} else {
enddtime = waypointp->GetCreationTime().addSecs(-time_offset);
}
- starttime = startdtime.toUTC().time();
- endtime = enddtime.toUTC().time();
+ QTime starttime = startdtime.toUTC().time();
+ QTime endtime = enddtime.toUTC().time();
gbfprintf(fout, "%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\n",
starttime.hour(), starttime.minute(), starttime.second(), starttime.msec(),
endtime.hour(), endtime.minute(), endtime.second(), endtime.msec());
subrip_wr_init(const QString& fname)
{
time_t gpstime_t;
- struct tm* ptm_gps;
stnum = 1;
if ((opt_gpstime != nullptr) && (opt_gpsdate != nullptr)) {
time(&gpstime_t);
- ptm_gps = gmtime(&gpstime_t);
+ struct tm* ptm_gps = gmtime(&gpstime_t);
if (opt_gpstime) {
sscanf(opt_gpstime, "%2d%2d%2d", &ptm_gps->tm_hour, &ptm_gps->tm_min, &ptm_gps->tm_sec);
}
void SwapDataFilter::swapdata_cb(const Waypoint* ref)
{
Waypoint* wpt = const_cast<Waypoint*>(ref);
- double x;
- x = wpt->latitude;
+ double x = wpt->latitude;
wpt->latitude = wpt->longitude;
wpt->longitude = x;
static void
waypoint_final()
{
- int via;
if (wpt_tmp == nullptr) {
return;
}
- via = wpt_tmp->wpt_flags.fmt_use ;
+ int via = wpt_tmp->wpt_flags.fmt_use;
wpt_tmp->wpt_flags.fmt_use = 0;
if (version < 2) { /* keep the old behaviour */
tef_read_comma_float(const QStringRef& value)
{
QString svalue = value.toString();
- int cidx;
- cidx = svalue.indexOf(',');
+ int cidx = svalue.indexOf(',');
if (cidx == -1) {
return svalue.toDouble();
}
int32_t utmz;
double utme, utmn;
char utmzc;
- char* tmpout1, *tmpout2;
+ char* tmpout2;
char* altout;
- fs_xml* fs_gpx;
waypoint_count++;
GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude,
&utme, &utmn, &utmz, &utmzc);
- tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0);
+ char* tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0);
if (wpt->altitude != unknown_alt) {
xasprintf(&altout, " alt:%d", (int)((altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude));
} else {
gbfputs("\n", file_out);
}
- fs_gpx = nullptr;
+ fs_xml* fs_gpx = nullptr;
if (includelogs) {
fs_gpx = (fs_xml*)fs_chain_find(wpt->fs, FS_GPX);
}
char desc[101];
char icon[101];
char* ibuf;
- Waypoint* wpt_tmp;
int line = 0;
while ((ibuf = gbfgetstr(file_in))) {
}
if (sscanf(ibuf, "%lf,%lf:%100[^:]:%100[^\n]",
&lon, &lat, icon, desc)) {
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
wpt_tmp->longitude = lon;
wpt_tmp->latitude = lat;
static void
data_write()
{
- double latsz,lonsz;
maxlat = -9999.0;
maxlon = -9999.0;
minlat = 9999.0;
waypt_disp_all(tiger_disp);
if (genurl) {
- gbfile* urlf;
-
- urlf = gbfopen(genurl, "w", MYNAME);
- latsz = fabs(maxlat - minlat);
- lonsz = fabs(maxlon - minlon);
+ gbfile* urlf = gbfopen(genurl, "w", MYNAME);
+ double latsz = fabs(maxlat - minlat);
+ double lonsz = fabs(maxlon - minlon);
/*
* Center the map along X and Y axis the midpoint of
data_read()
{
char* buff;
- char* s;
- Waypoint* wpt_tmp;
- int i;
int linecount = 0;
while ((buff = gbfgetstr(file_in))) {
/* skip the line if it contains "sHyperLink" as it is a header (I hope :) */
if ((strlen(buff)) && (strstr(buff, "sHyperLink") == nullptr)) {
- wpt_tmp = new Waypoint;
+ Waypoint* wpt_tmp = new Waypoint;
/* data delimited by tabs, not enclosed in quotes. */
- s = buff;
+ char* s = buff;
s = csv_lineparse(s, "\t", "", linecount);
- i = 0;
+ int i = 0;
while (s) {
switch (i) {
static void
data_read()
{
- int rectype;
long recsize;
long x;
long y;
char* desc;
Waypoint* wpt_tmp;
while (!gbfeof(file_in)) {
- rectype = read_char(file_in);
+ int rectype = read_char(file_in);
if (rectype == EOF) {
fatal(MYNAME ":Unexpected EOF.");
}
compute_blocks(struct hdr* start, int count,
double minlon, double maxlon, double minlat, double maxlat)
{
- struct blockheader* newblock;
-
- newblock = (struct blockheader*)xcalloc(sizeof(*newblock), 1);
+ struct blockheader* newblock = (struct blockheader*)xcalloc(sizeof(*newblock), 1);
newblock->start = start;
newblock->count = count;
newblock->minlon = minlon;
tpg_read()
{
char buff[MAXTPGSTRINGSIZE + 1];
- double lat, lon, elev;
double amt;
- short int pointcount;
- pointcount = gbfgetint16(tpg_file_in);
+ short int pointcount = gbfgetint16(tpg_file_in);
/* the rest of the header */
gbfread(&buff[0], 19, 1, tpg_file_in);
/* coordinates are in NAD27/CONUS datum */
/* 8 bytes - longitude, sign swapped */
- lon = gbfgetdbl(tpg_file_in);
+ double lon = gbfgetdbl(tpg_file_in);
/* 8 bytes - latitude */
- lat = gbfgetdbl(tpg_file_in);
+ double lat = gbfgetdbl(tpg_file_in);
/* swap sign before we do datum conversions */
lon *= -1.0;
/* 2 bytes - elevation in feet */
- elev = FEET_TO_METERS(gbfgetint16(tpg_file_in));
+ double elev = FEET_TO_METERS(gbfgetint16(tpg_file_in));
/* convert incoming NAD27/CONUS coordinates to WGS84 */
GPS_Math_Known_Datum_To_WGS84_M(
{
double lon, lat;
double amt;
- short int elev;
char tbuf[64];
- char c,ocount;
+ char ocount;
QString shortname;
QString description;
int i;
lon *= -1.0;
/* convert meters back to feets */
- elev = (short int) METERS_TO_FEET(wpt->altitude);
+ short int elev = (short int) METERS_TO_FEET(wpt->altitude);
/* 1 bytes stringsize for shortname */
- c = shortname.length();
+ char c = shortname.length();
ocount = 0;
/*
* It's reported the only legal characters are upper case
static void
tpg_write()
{
- int s;
unsigned char header_bytes[] = { 0xFF, 0xFF, 0x01, 0x00, 0x0D,
0x00, 0x43, 0x54, 0x6F, 0x70,
0x6F, 0x57, 0x61, 0x79, 0x70,
0x6F, 0x69, 0x6E, 0x74
};
- s = waypt_count();
+ int s = waypt_count();
if (global_opts.synthesize_shortnames) {
setshort_length(mkshort_handle, 32);
{
unsigned char string_size;
- char* string_buffer;
const char* v3_id_string = "TOPO! Ver";
/* read the id string */
gbfread(&string_size, 1, 1, tpo_file_in);
- string_buffer = (char*) xmalloc(string_size+1);
+ char* string_buffer = (char*) xmalloc(string_size+1);
gbfread(string_buffer, 1, string_size, tpo_file_in);
/* terminate the string */
static void tpo_read_2_x()
{
char buff[16];
- short track_count, waypoint_count;
/* track count */
- track_count = gbfgetint16(tpo_file_in);
+ short track_count = gbfgetint16(tpo_file_in);
/*fprintf(stderr,"track_count:%d\n", track_count);*/
gbfread(&buff[0], 1, 8, tpo_file_in);
/* number of route points */
- waypoint_count = gbfgetint16(tpo_file_in);
+ short waypoint_count = gbfgetint16(tpo_file_in);
/* allocate temporary memory for the waypoint deltas */
std::vector<short> lat_delta(waypoint_count);
//
static int tpo_read_int()
{
- unsigned char val;
-
- val = (unsigned char) gbfgetc(tpo_file_in);
+ unsigned char val = (unsigned char) gbfgetc(tpo_file_in);
switch (val) {
static int tpo_find_block(unsigned int block_desired)
{
unsigned int block_type;
- unsigned int block_offset;
// Skip 512 byte fixed-length header
- block_offset = 512;
+ unsigned int block_offset = 512;
do {
//
static Waypoint* tpo_convert_ll(int lat, int lon)
{
- double latitude;
- double longitude;
- Waypoint* waypoint_temp;
-
-
- waypoint_temp = new Waypoint;
+ Waypoint* waypoint_temp = new Waypoint;
- latitude = (double)lat / 0x800000;
- longitude = (double)lon / 0x800000;
+ double latitude = (double)lat / 0x800000;
+ double longitude = (double)lon / 0x800000;
//printf("lat: %f\tlon: %f\n", latitude, longitude);
//
static void tpo_process_tracks()
{
- unsigned int track_count, track_style_count;
const int DEBUG = 0;
if (DEBUG) {
return;
}
// Read the number of track styles.
- track_style_count = tpo_read_int(); // 8 bit value
+ unsigned int track_style_count = tpo_read_int(); // 8 bit value
if (DEBUG) {
printf("Unpacking %u track styles...\n",track_style_count);
}
// Read the number of tracks. Can be 8/16/32-bit value.
- track_count = tpo_read_int();
+ unsigned int track_count = tpo_read_int();
if (DEBUG) {
printf("Total Tracks: %u\n", track_count);
// Read/process each track in the file
//
for (unsigned ii = 0; ii < track_count; ii++) {
- unsigned int line_type;
- unsigned int track_style;
- unsigned int name_length;
- unsigned int track_byte_count;
- int llvalid;
- unsigned char* buf;
- int lonscale;
- int latscale;
int lat = 0;
int lon = 0;
- route_head* track_temp;
char rgb[7],bgr[7];
// Allocate the track struct
- track_temp = route_head_alloc();
+ route_head* track_temp = route_head_alloc();
track_add_head(track_temp);
//UNKNOWN DATA LENGTH
- line_type = tpo_read_int(); // always zero??
+ unsigned int line_type = tpo_read_int(); // always zero??
// Can be 8/16/32-bit value (defined in 2012, ignored before then)
- track_style = tpo_read_int(); // index into freehand route styles defined in this .tpo file
+ unsigned int track_style = tpo_read_int(); // index into freehand route styles defined in this .tpo file
track_style -= 1; // STARTS AT 1, whereas style arrays start at 0
// Can be 8/16/32-bit value - never used?
track_length = tpo_read_int();
//UNKNOWN DATA LENGTH
- name_length = tpo_read_int();
+ unsigned int name_length = tpo_read_int();
QString track_name;
if (name_length) {
gbfread(track_name, 1, name_length, tpo_file_in);
track_temp->rte_num = ii + 1;
//UNKNOWN DATA LENGTH
- track_byte_count = tpo_read_int();
+ unsigned int track_byte_count = tpo_read_int();
// Read the number of bytes specified for the track. These
// contain scaling factors, long/lat's, and offsets from
// proper place for the next track.
// Read the track bytes into a buffer
- buf = (unsigned char*) xmalloc(track_byte_count);
+ unsigned char* buf = (unsigned char*) xmalloc(track_byte_count);
gbfread(buf, 1, track_byte_count, tpo_file_in);
- latscale=0;
- lonscale=0;
+ int latscale = 0;
+ int lonscale = 0;
// Process the track bytes
- llvalid = 0;
+ int llvalid = 0;
for (unsigned int jj = 0; jj < track_byte_count;) {
Waypoint* waypoint_temp;
//
static void tpo_process_waypoints()
{
- unsigned int waypoint_count;
-
-
-//printf("Processing Waypoints...\n");
+ //printf("Processing Waypoints...\n");
// Find block 0x0e0000 (GPS-Waypoints)
if (tpo_find_block(0x0e0000)) {
}
// Read the number of waypoints. 8/16/32-bit value.
- waypoint_count = tpo_read_int();
+ unsigned int waypoint_count = tpo_read_int();
//printf("Total Waypoints: %d\n", waypoint_count);
// Read/process each waypoint in the file
for (unsigned int ii = 0; ii < waypoint_count; ii++) {
- Waypoint* waypoint_temp;
- Waypoint* waypoint_temp2;
- unsigned int name_length;
- int lat;
- int lon;
- int altitude;
-
-//UNKNOWN DATA LENGTH
+ //UNKNOWN DATA LENGTH
(void)tpo_read_int(); // 0x00
//UNKNOWN DATA LENGTH
//UNKNOWN DATA LENGTH
// Fetch name length
- name_length = tpo_read_int();
+ unsigned int name_length = tpo_read_int();
QString waypoint_name;
if (name_length) {
gbfread(waypoint_name, 1, name_length, tpo_file_in);
//UNKNOWN DATA LENGTH
(void)tpo_read_int();
- lon = gbfgetint32(tpo_file_in);
- lat = gbfgetint32(tpo_file_in);
+ int lon = gbfgetint32(tpo_file_in);
+ int lat = gbfgetint32(tpo_file_in);
// Allocate space for waypoint and store lat/lon
- waypoint_temp = tpo_convert_ll(lat, lon);
+ Waypoint* waypoint_temp = tpo_convert_ll(lat, lon);
// Assign the waypoint name
waypoint_temp->shortname = waypoint_name;
// Grab the altitude in centimeters
- altitude = gbfgetint32(tpo_file_in);
+ int altitude = gbfgetint32(tpo_file_in);
// The original untested check for unknown altitude was for 0xfffd000c (-196596 cm),
// but a test case submitted later used 0xffce0000 (-3276800 cm).
if (altitude == -3276800) { // Unknown altitude
// For routes (later), we need a duplicate of each waypoint
// indexed by the order we read them in.
- waypoint_temp2 = new Waypoint(*waypoint_temp);
+ Waypoint* waypoint_temp2 = new Waypoint(*waypoint_temp);
// Attach the copy to our index
tpo_wp_index[tpo_index_ptr++] = waypoint_temp2;
//
static void tpo_process_map_notes()
{
- unsigned int waypoint_count;
-
-
-//printf("Processing Map Notes...\n");
+ //printf("Processing Map Notes...\n");
// Find block 0x090000 (Map Notes)
if (tpo_find_block(0x090000)) {
}
// Read the number of waypoints. 8/16/32-bit value.
- waypoint_count = tpo_read_int();
+ unsigned int waypoint_count = tpo_read_int();
//printf("Elements: %d\n", waypoint_count);
// Process each waypoint
for (unsigned int ii = 0; ii < waypoint_count; ii++) {
- int lat;
- int lon;
- unsigned int name_length;
- Waypoint* waypoint_temp;
- unsigned int num_bytes;
-
-
-//UNKNOWN DATA LENGTH
+ //UNKNOWN DATA LENGTH
(void)tpo_read_int();
- lon = gbfgetint32(tpo_file_in);
- lat = gbfgetint32(tpo_file_in);
+ int lon = gbfgetint32(tpo_file_in);
+ int lat = gbfgetint32(tpo_file_in);
// Allocate space for waypoint and store lat/lon
- waypoint_temp = tpo_convert_ll(lat, lon);
+ Waypoint* waypoint_temp = tpo_convert_ll(lat, lon);
// Assign a generic waypoint name
waypoint_temp->shortname = QString("NOTE %1").arg(ii + 1);
//UNKNOWN DATA LENGTH
// Fetch comment length
- name_length = tpo_read_int();
+ unsigned int name_length = tpo_read_int();
if (name_length) {
QString comment;
// Number of bytes to skip until next element or end of
// block. May be 8/16/32 bits.
- num_bytes = tpo_read_int();
+ unsigned int num_bytes = tpo_read_int();
//printf("num_bytes: %x\n", num_bytes);
for (unsigned int jj = 0; jj < num_bytes; jj++) {
(void) gbfgetc(tpo_file_in); // Skip bytes
//
static void tpo_process_symbols()
{
- unsigned int waypoint_count;
-
-
-//printf("Processing Symbols...\n");
+ //printf("Processing Symbols...\n");
// Find block 0x040000 (Symbols)
if (tpo_find_block(0x040000)) {
}
// Read the number of waypoints. 8/16/32-bit value.
- waypoint_count = tpo_read_int();
+ unsigned int waypoint_count = tpo_read_int();
//printf("Elements: %d\n", waypoint_count);
// Process each waypoint
for (unsigned int ii = 0; ii < waypoint_count; ii++) {
- int lat;
- int lon;
- Waypoint* waypoint_temp;
-
-
-//UNKNOWN DATA LENGTH
+ //UNKNOWN DATA LENGTH
(void)tpo_read_int();
//UNKNOWN DATA LENGTH
(void)tpo_read_int();
- lon = gbfgetint32(tpo_file_in);
- lat = gbfgetint32(tpo_file_in);
+ int lon = gbfgetint32(tpo_file_in);
+ int lat = gbfgetint32(tpo_file_in);
// Allocate space for waypoint and store lat/lon
- waypoint_temp = tpo_convert_ll(lat, lon);
+ Waypoint* waypoint_temp = tpo_convert_ll(lat, lon);
// Assign a generic waypoint name
waypoint_temp->shortname = QString("SYM %1").arg(ii + 1);
//
static void tpo_process_text_labels()
{
- unsigned int waypoint_count;
-
-
-//printf("Processing Text Labels...\n");
+ //printf("Processing Text Labels...\n");
// Find block 0x080000 (Text Labels)
if (tpo_find_block(0x080000)) {
}
// Read the number of waypoints. 8/16/32-bit value.
- waypoint_count = tpo_read_int();
+ unsigned int waypoint_count = tpo_read_int();
//printf("Elements: %d\n", waypoint_count);
// Process each waypoint
for (unsigned int ii = 0; ii < waypoint_count; ii++) {
- int lat;
- int lon;
- unsigned int name_length;
- Waypoint* waypoint_temp;
-
-
-//UNKNOWN DATA LENGTH
+ //UNKNOWN DATA LENGTH
(void)tpo_read_int();
//UNKNOWN DATA LENGTH
(void)tpo_read_int();
- lon = gbfgetint32(tpo_file_in);
- lat = gbfgetint32(tpo_file_in);
+ int lon = gbfgetint32(tpo_file_in);
+ int lat = gbfgetint32(tpo_file_in);
// Allocate space for waypoint and store lat/lon
- waypoint_temp = tpo_convert_ll(lat, lon);
+ Waypoint* waypoint_temp = tpo_convert_ll(lat, lon);
// Assign a generic waypoint name
waypoint_temp->shortname = QString("TXT %1").arg(ii + 1);
// Fetch comment length
//UNKNOWN DATA LENGTH
- name_length = tpo_read_int();
+ unsigned int name_length = tpo_read_int();
if (name_length) {
QString comment;
gbfread(comment, 1, name_length, tpo_file_in);
//
static void tpo_process_routes()
{
- unsigned int route_count;
-
-
-//printf("Processing Routes...\n");
+ //printf("Processing Routes...\n");
// Find block 0x0f0000 (GPS-Routes)
if (tpo_find_block(0x0f0000)) {
}
// Read the number of routes. 8/16/32-bit value
- route_count = tpo_read_int();
+ unsigned int route_count = tpo_read_int();
//printf("Total Routes: %d\n", route_count);
// Read/process each route in the file
//
for (unsigned int ii = 0; ii < route_count; ii++) {
- unsigned int waypoint_cnt;
- route_head* route_temp;
-
-
// Allocate the route struct
- route_temp = route_head_alloc();
+ route_head* route_temp = route_head_alloc();
route_add_head(route_temp);
//UNKNOWN DATA LENGTH
// Fetch the number of waypoints in this route. 8/16/32-bit
// value.
- waypoint_cnt = tpo_read_int();
+ unsigned int waypoint_cnt = tpo_read_int();
// Run through the list of waypoints, look up each in our
// index, then add the waypoint to this route.
//
for (unsigned int jj = 0; jj < waypoint_cnt; jj++) {
- Waypoint* waypoint_temp;
- unsigned int val;
-
-
-//UNKNOWN DATA LENGTH
+ //UNKNOWN DATA LENGTH
// Fetch the index to the waypoint
- val = tpo_read_int();
+ unsigned int val = tpo_read_int();
//printf("val: %x\t\t", val);
// Duplicate a waypoint from our index of waypoints.
- waypoint_temp = new Waypoint(*tpo_wp_index[val-1]);
+ Waypoint* waypoint_temp = new Waypoint(*tpo_wp_index[val-1]);
// Add the waypoint to the route
route_add_wpt(route_temp, waypoint_temp);
tpo_track_disp(const Waypoint* waypointp)
{
double lat, lon, amt, x, y, z;
- short lat_delta, lon_delta;
/* fprintf(stderr, "%f/%f\n", waypointp->latitude, waypointp->longitude); */
lon *= -1.0;
/* longitude delta from first route point */
- lon_delta = (short)((first_track_waypoint_lon - lon) / output_track_lon_scale);
+ short lon_delta = (short)((first_track_waypoint_lon - lon) / output_track_lon_scale);
gbfputint16(lon_delta, tpo_file_out);
/* latitude delta from first route point */
- lat_delta = (short)((first_track_waypoint_lat - lat) / output_track_lat_scale);
+ short lat_delta = (short)((first_track_waypoint_lat - lat) / output_track_lat_scale);
gbfputint16(lat_delta, tpo_file_out);
/*
int TrackFilter::trackfilter_parse_time_opt(const char* arg)
{
- time_t t0, t1;
int sign = 1;
const char* cin = arg;
char c;
- t0 = t1 = 0;
+ time_t t0 = 0;
+ time_t t1 = 0;
while ((c = *cin++)) {
time_t seconds;
void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track) /* callback for track_disp_all */
{
- int i;
- Waypoint* wpt, *prev;
queue* elem, *tmp;
if (track->rte_waypt_ct == 0) {
track_list[track_ct].track = const_cast<route_head*>(track);
- i = 0;
- prev = nullptr;
+ int i = 0;
+ Waypoint* prev = nullptr;
QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) {
track_pts++;
- wpt = (Waypoint*)elem;
+ Waypoint* wpt = (Waypoint*)elem;
if (!wpt->creation_time.isValid()) {
timeless_pts++;
}
{
if (strchr(opt_title, '%') != nullptr) {
struct tm tm;
- Waypoint* wpt;
if (track->rte_waypt_ct == 0) {
tm = *localtime(&default_time);
} else {
- wpt = (Waypoint*) QUEUE_FIRST((queue*)&track->waypoint_list);
+ Waypoint* wpt = (Waypoint*) QUEUE_FIRST((queue*)&track->waypoint_list);
time_t t = wpt->GetCreationTime().toTime_t();
tm = *localtime(&t);
}
void TrackFilter::trackfilter_pack()
{
int i, j;
- trkflt_t prev;
- route_head* master;
for (i = 1, j = 0; i < track_ct; i++, j++) {
- prev = track_list[j];
+ trkflt_t prev = track_list[j];
if (prev.last_time >= track_list[i].first_time) {
fatal(MYNAME "-pack: Tracks overlap in time! %s >= %s at %d\n",
qPrintable(prev.last_time.toString()),
/* we fill up the first track by all other track points */
- master = track_list[0].track;
+ route_head* master = track_list[0].track;
for (i = 1; i < track_ct; i++) {
queue* elem, *tmp;
void TrackFilter::trackfilter_merge()
{
- int i, j, dropped;
+ int i;
queue* elem, *tmp;
- Waypoint** buff;
- Waypoint* prev, *wpt;
+ Waypoint* wpt;
route_head* master = track_list[0].track;
if (track_pts-timeless_pts < 1) {
return;
}
- buff = (Waypoint**)xcalloc(track_pts-timeless_pts, sizeof(*buff));
+ Waypoint** buff = (Waypoint**)xcalloc(track_pts-timeless_pts, sizeof(*buff));
- j = 0;
+ int j = 0;
for (i = 0; i < track_ct; i++) { /* put all points into temp buffer */
route_head* track = track_list[i].track;
QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) {
qsort(buff, track_pts-timeless_pts, sizeof(*buff), trackfilter_merge_qsort_cb);
- dropped = timeless_pts;
- prev = nullptr;
+ int dropped = timeless_pts;
+ Waypoint* prev = nullptr;
for (i = 0; i < track_pts-timeless_pts; i++) {
buff[i]->extra_data = nullptr;
void TrackFilter::trackfilter_split()
{
- route_head* curr;
route_head* master = track_list[0].track;
int count = master->rte_waypt_ct;
- Waypoint** buff;
Waypoint* wpt;
queue* elem, *tmp;
int i, j;
trackfilter_split_init_rte_name(master, track_list[0].first_time);
- buff = (Waypoint**) xcalloc(count, sizeof(*buff));
+ Waypoint** buff = (Waypoint**) xcalloc(count, sizeof(*buff));
i = 0;
QUEUE_FOR_EACH((queue*)&master->waypoint_list, elem, tmp) {
buff[i++] = wpt;
}
- curr = nullptr; /* will be set by first new track */
+ route_head* curr = nullptr; /* will be set by first new track */
for (i=0, j=1; j<count; i++, j++) {
int new_track_flag;
void TrackFilter::trackfilter_move()
{
queue* elem, *tmp;
- Waypoint* wpt;
- time_t delta;
- delta = trackfilter_parse_time_opt(opt_move);
+ time_t delta = trackfilter_parse_time_opt(opt_move);
if (delta == 0) {
return;
}
for (int i = 0; i < track_ct; i++) {
route_head* track = track_list[i].track;
QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) {
- wpt = (Waypoint*)elem;
+ Waypoint* wpt = (Waypoint*)elem;
wpt->creation_time += delta;
}
void TrackFilter::trackfilter_synth()
{
queue* elem, *tmp;
- Waypoint* wpt;
double last_course_lat;
double last_course_lon;
double last_speed_lat;
double last_speed_lon;
time_t last_speed_time;
- int first;
- fix_type fix;
int nsats = 0;
- fix = trackfilter_parse_fix(&nsats);
+ fix_type fix = trackfilter_parse_fix(&nsats);
for (int i = 0; i < track_ct; i++) {
route_head* track = track_list[i].track;
- first = 1;
+ int first = 1;
QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) {
- wpt = (Waypoint*)elem;
+ Waypoint* wpt = (Waypoint*)elem;
if (opt_fix) {
wpt->fix = fix;
if (wpt->sat == 0) {
time_t TrackFilter::trackfilter_range_check(const char* timestr)
{
- int i;
char fmt[20];
char c;
- const char* cin;
struct tm time;
- i = 0;
+ int i = 0;
strncpy(fmt, "00000101000000", sizeof(fmt));
- cin = timestr;
+ const char* cin = timestr;
while ((c = *cin++)) {
if (fmt[i] == '\0') {
{
time_t start, stop;
queue* elem, *tmp;
- int dropped, inside = 0;
if (opt_start != nullptr) {
start = trackfilter_range_check(opt_start);
stop = 0x7FFFFFFF;
}
- dropped = inside = 0;
+ int dropped = 0;
+ int inside = 0;
for (int i = 0; i < track_ct; i++) {
route_head* track = track_list[i].track;
void TrackFilter::trackfilter_trk2seg()
{
- int first;
- route_head* master;
-
- master = track_list[0].track;
+ route_head* master = track_list[0].track;
for (int i = 1; i < track_ct; i++) {
queue* elem, *tmp;
route_head* curr = track_list[i].track;
- first = 1;
+ int first = 1;
QUEUE_FOR_EACH((queue*)&curr->waypoint_list, elem, tmp) {
Waypoint* wpt = (Waypoint*)elem;
TrackFilter::faketime_t TrackFilter::trackfilter_faketime_check(const char* timestr)
{
- int i, j;
char fmtstart[20];
char fmtstep[20];
char c;
- const char* cin;
struct tm time;
bool timeparse = true;
faketime_t result;
result.force = false;
- i = j = 0;
+ int i = 0;
+ int j = 0;
strncpy(fmtstart, "00000101000000", sizeof(fmtstart));
strncpy(fmtstep, "00000000000000", sizeof(fmtstep));
- cin = timestr;
+ const char* cin = timestr;
while ((c = *cin++)) {
if (c=='f') {
{
RteHdFunctor<TrackFilter> trackfilter_minpoint_list_cb_f(this, &TrackFilter::trackfilter_minpoint_list_cb);
- int opts, something_done;
-
if (track_ct == 0) {
return; /* no track(s), no fun */
}
- opts = trackfilter_opt_count();
+ int opts = trackfilter_opt_count();
if (opts == 0) {
opts = -1; /* flag for do "pack" by default */
}
}
}
- something_done = 0;
+ int something_done = 0;
if ((opt_pack != nullptr) || (opts == -1)) { /* call our default option */
trackfilter_pack();
void TransformFilter::transform_waypoints()
{
- route_head* rte;
-
- rte = route_head_alloc();
+ route_head* rte = route_head_alloc();
switch (current_target) {
case 'R':
route_add_head(rte);
static int
unicsv_strrcmp(const char* s1, const char* s2)
{
- int l1, l2;
- l1 = strlen(s1);
- l2 = strlen(s2);
+ int l1 = strlen(s1);
+ int l2 = strlen(s2);
if ((l1 - l2) >= 0) {
return strcmp(s1 + (l1 - l2), s2);
} else {
static time_t
unicsv_parse_date(const char* str, int* consumed)
{
- int p1, p2, p3, ct;
+ int p1, p2, p3;
char sep[2];
struct tm tm;
int lconsumed = 0;
memset(&tm, 0, sizeof(tm));
- ct = sscanf(str, "%d%1[-.//]%d%1[-.//]%d%n", &p1, sep, &p2, sep, &p3, &lconsumed);
+ int ct = sscanf(str, "%d%1[-.//]%d%1[-.//]%d%n", &p1, sep, &p2, sep, &p3, &lconsumed);
if (consumed && lconsumed) {
*consumed = lconsumed;
}
static time_t
unicsv_parse_time(const char* str, int* usec, time_t* date)
{
- int hour, min, ct, sec;
+ int hour, min, sec;
int consumed = 0;
double us;
char sep[2];
- time_t ldate;
/* If we have somethine we're pretty sure is a date, parse that
* first, skip over it, and pass that back to the caller)
*/
- ldate = unicsv_parse_date(str, &consumed);
+ time_t ldate = unicsv_parse_date(str, &consumed);
if (consumed && ldate) {
str += consumed;
if (date) {
*date = ldate;
}
}
- ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &us);
+ int ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &us);
is_fatal(ct < 5, MYNAME ": Could not parse time string (%s).\n", str);
if (ct == 6) {
*usec = lround((us * 1000000));
static void
unicsv_parse_one_line(char* ibuf)
{
- int column;
int utm_zone = -9999;
double utm_easting = 0;
double utm_northing = 0;
wpt->longitude = unicsv_unknown;
memset(&ymd, 0, sizeof(ymd));
- column = -1;
+ int column = -1;
QString s;
while ((s = csv_lineparse(ibuf, unicsv_fieldsep, "\"", 0)), !s.isNull()) {
if (++column >= unicsv_fields_tab.size()) {
static void
unicsv_waypt_enum_cb(const Waypoint* wpt)
{
- garmin_fs_t* gmsd;
-
const QString& shortname = wpt->shortname;
- gmsd = GMSD_FIND(wpt);
+ garmin_fs_t* gmsd = GMSD_FIND(wpt);
if (!shortname.isEmpty()) {
gb_setbit(&unicsv_outp_flags, fld_shortname);
{
double lat, lon, alt;
char* cout = nullptr;
- garmin_fs_t* gmsd;
const geocache_data* gc_data = nullptr;
unicsv_waypt_ct++;
QString shortname = wpt->shortname;
- gmsd = GMSD_FIND(wpt);
+ garmin_fs_t* gmsd = GMSD_FIND(wpt);
if (unicsv_datum_idx == DATUM_WGS84) {
lat = wpt->latitude;
break;
case grid_lat_lon_dms: {
- char* sep;
- QString tmp;
cout = pretty_deg_format(lat, lon, 's', unicsv_fieldsep, 0);
- sep = strchr(cout, ',');
+ char* sep = strchr(cout, ',');
*sep = '\0';
- tmp = strenquote(cout, UNICSV_QUOT_CHAR);
+ QString tmp = strenquote(cout, UNICSV_QUOT_CHAR);
gbfprintf(fout, "%s%s", CSTR(tmp), unicsv_fieldsep);
tmp = strenquote(sep+1, UNICSV_QUOT_CHAR);
gbfputs(tmp, fout);
{
size_t newlen = 0;
const char* cin = str;
- char* newstr;
while ((newlen < sz) && (*cin != '\0')) {
newlen++;
cin++;
}
- newstr = (char*) xmalloc(newlen + 1);
+ char* newstr = (char*) xmalloc(newlen + 1);
memcpy(newstr, str, newlen);
newstr[newlen] = 0;
xstrappend(char* src, const char* newd)
#endif
{
- size_t newsz;
-
if (!src) {
return xxstrdup(newd, file, line);
}
return xxstrdup(src, file, line);
}
- newsz = strlen(src) + strlen(newd) + 1;
+ size_t newsz = strlen(src) + strlen(newd) + 1;
src = (char*) xxrealloc(src, newsz, file, line);
strcat(src, newd);
FILE*
xfopen(const char* fname, const char* type, const char* errtxt)
{
- FILE* f;
int am_writing = strchr(type, 'w') != nullptr;
if (fname == nullptr) {
if (0 == strcmp(fname, "-")) {
return am_writing ? stdout : stdin;
}
- f = ufopen(QString::fromUtf8(fname), type);
+ FILE* f = ufopen(QString::fromUtf8(fname), type);
if (nullptr == f) {
fatal("%s cannot open '%s' for %s. Error was '%s'.\n",
errtxt, fname,
xasprintf(char** strp, const char* fmt, ...)
{
va_list args;
- int res;
va_start(args, fmt);
- res = xvasprintf(strp, fmt, args);
+ int res = xvasprintf(strp, fmt, args);
va_end(args);
return res;
xasprintf(QString* strp, const char* fmt, ...)
{
va_list args;
- int res;
va_start(args, fmt);
char* cstrp;
- res = xvasprintf(&cstrp, fmt, args);
+ int res = xvasprintf(&cstrp, fmt, args);
*strp = cstrp;
xfree(cstrp);
va_end(args);
# define FIRSTSIZE 1
#endif
char* buf = nullptr;
- int bufsize;
char* newbuf;
size_t nextsize = 0;
int outsize;
va_list args;
- bufsize = 0;
+ int bufsize = 0;
for (;;) {
if (bufsize == 0) {
if ((buf = (char*) xmalloc(FIRSTSIZE)) == nullptr) {
char*
lrtrim(char* buff)
{
- char* c;
-
if (buff[0] == '\0') {
return buff;
}
- c = buff + strlen(buff);
+ char* c = buff + strlen(buff);
while ((c >= buff) && ((unsigned char)*c <= ' ')) {
*c-- = '\0';
}
int
str_match(const char* str, const char* match)
{
- const char* m, *s;
-
- s = str;
- m = match;
+ const char* s = str;
+ const char* m = match;
while (*m || *s) {
switch (*m) {
}
do {
- const char* mx, *sx;
-
while (*s && (*s != *m)) {
s++;
}
return 0;
}
- sx = s + 1;
- mx = m + 1;
+ const char* sx = s + 1;
+ const char* mx = m + 1;
while (*sx) {
if (*mx == '\\') { /* ? escaped ? */
time_t
mkgmtime(struct tm* t)
{
- short month, year;
- time_t result;
static int m_to_d[12] =
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
- month = t->tm_mon;
- year = t->tm_year + month / 12 + 1900;
+ short month = t->tm_mon;
+ short year = t->tm_year + month / 12 + 1900;
month %= 12;
if (month < 0) {
year -= 1;
month += 12;
}
- result = (year - 1970) * 365 + m_to_d[month];
+ time_t result = (year - 1970) * 365 + m_to_d[month];
if (month <= 1) {
year -= 1;
}
/* Magellan and PCX formats use this DDMM.mm format */
double ddmm2degrees(double pcx_val)
{
- double minutes;
- signed int deg;
- deg = (signed int)(pcx_val / 100.0);
- minutes = (((pcx_val / 100.0) - deg) * 100.0) / 60.0;
+ signed int deg = (signed int)(pcx_val / 100.0);
+ double minutes = (((pcx_val / 100.0) - deg) * 100.0) / 60.0;
return (double) deg + minutes;
}
double degrees2ddmm(double deg_val)
{
- signed int deg;
- deg = (signed int) deg_val;
+ signed int deg = (signed int) deg_val;
return (deg * 100.0) + ((deg_val - deg) * 60.0);
}
char*
strsub(const char* s, const char* search, const char* replace)
{
- const char* p;
int len = strlen(s);
int slen = strlen(search);
int rlen = strlen(replace);
- char* d;
- p = strstr(s, search);
+ const char* p = strstr(s, search);
if (!slen || !p) {
return nullptr;
}
- d = (char*) xmalloc(len + rlen + 1);
+ char* d = (char*) xmalloc(len + rlen + 1);
/* Copy first part */
len = p - s;
gstrsub(const char* s, const char* search, const char* replace)
{
int ooffs = 0;
- char* o;
const char* c;
const char* src = s;
int olen = strlen(src);
int slen = strlen(search);
int rlen = strlen(replace);
- o = (char*) xmalloc(olen + 1);
+ char* o = (char*) xmalloc(olen + 1);
while ((c = strstr(src, search))) {
olen += (rlen - slen);
char*
convert_human_date_format(const char* human_datef)
{
- char* result, *cout;
- char prev;
- int ylen;
-
- result = (char*) xcalloc((2*strlen(human_datef)) + 1, 1);
- cout = result;
- prev = '\0';
- ylen = 0;
+ char* result = (char*) xcalloc((2*strlen(human_datef)) + 1, 1);
+ char* cout = result;
+ char prev = '\0';
+ int ylen = 0;
for (const char* cin = human_datef; *cin; cin++) {
char okay = 1;
char*
convert_human_time_format(const char* human_timef)
{
- char* result, *cout;
- char prev;
-
- result = (char*) xcalloc((2*strlen(human_timef)) + 1, 1);
- cout = result;
- prev = '\0';
+ char* result = (char*) xcalloc((2*strlen(human_timef)) + 1, 1);
+ char* cout = result;
+ char prev = '\0';
for (const char* cin = human_timef; *cin; cin++) {
int okay = 1;
char*
pretty_deg_format(double lat, double lon, char fmt, const char* sep, int html)
{
- double latmin, lonmin, latsec, lonsec;
- int latint, lonint;
- char latsig, lonsig;
char* result;
- latsig = lat < 0 ? 'S':'N';
- lonsig = lon < 0 ? 'W':'E';
- latint = abs((int) lat);
- lonint = abs((int) lon);
- latmin = 60.0 * (fabs(lat) - latint);
- lonmin = 60.0 * (fabs(lon) - lonint);
- latsec = 60.0 * (latmin - floor(latmin));
- lonsec = 60.0 * (lonmin - floor(lonmin));
+ char latsig = lat < 0 ? 'S':'N';
+ char lonsig = lon < 0 ? 'W':'E';
+ int latint = abs((int) lat);
+ int lonint = abs((int) lon);
+ double latmin = 60.0 * (fabs(lat) - latint);
+ double lonmin = 60.0 * (fabs(lon) - lonint);
+ double latsec = 60.0 * (latmin - floor(latmin));
+ double lonsec = 60.0 * (lonmin - floor(lonmin));
if (sep == nullptr) {
sep = " "; /* default " " */
}
char*
strip_nastyhtml(const QString& in)
{
- char* returnstr, *sp;
- char* lcstr, *lcp;
+ char* returnstr;
+ char* lcstr;
- sp = returnstr = xstrdup(in);
- lcp = lcstr = strlower(xstrdup(in));
+ char* sp = returnstr = xstrdup(in);
+ char* lcp = lcstr = strlower(xstrdup(in));
while (lcp = strstr(lcstr, "<body>"), nullptr != lcp) {
sp = returnstr + (lcp - lcstr) ; /* becomes <! > */
doc.setHtml(in->utfstring);
return xstrdup(CSTR(doc.toPlainText().simplified()));
#else
- char* outstring, *out;
- char* incopy, *instr;
+ char* out;
+ char* instr;
char tag[8];
unsigned short int taglen = 0;
- incopy = instr = xstrdup(in->utfstring);
+ char* incopy = instr = xstrdup(in->utfstring);
if (!in->is_html) {
return instr;
}
/*
* We only shorten, so just dupe the input buf for space.
*/
- outstring = out = xstrdup(in->utfstring);
+ char* outstring = out = xstrdup(in->utfstring);
tag[0] = 0;
while (*instr) {
char*
entitize(const char* str, bool is_html)
{
- int elen, ecount, nsecount;
- entity_types* ep;
- const char* cp;
- char* p, * tmp, * xstr;
+ int ecount;
+ int nsecount;
+ char* p;
+ char* tmp;
+ char* xstr;
int bytes = 0;
int value = 0;
- ep = stdentities;
- elen = ecount = nsecount = 0;
+ entity_types* ep = stdentities;
+ int elen = ecount = nsecount = 0;
/* figure # of entity replacements and additional size. */
while (ep->text) {
- cp = str;
+ const char* cp = str;
while ((cp = strstr(cp, ep->text)) != nullptr) {
elen += strlen(ep->entity) - strlen(ep->text);
ecount++;
char text[200]; /* used to read the header line, which is normal text */
} line;
int lc = 0;
- route_head* track;
v900_log("%s\n",__func__);
v900_log("header line: %s",line.text);
v900_log("is_advance_mode=%d\n",is_advanced_mode);
- track = route_head_alloc();
+ route_head* track = route_head_alloc();
track->rte_name = "V900 tracklog";
track->rte_desc = "V900 GPS tracklog data";
track_add_head(track);
while (true) {
- Waypoint* wpt;
- char c;
int bad = 0;
int record_len = is_advanced_mode ? sizeof(line.adv) : sizeof(line.bas);
if (fread(&line, record_len, 1, fin) != 1) {
line.bas.cr = 0; /* null terminate vox field */
}
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
/* lat is a string in the form: 31.768380N */
- c = line.bas.common.latitude_NS; /* N/S */
+ char c = line.bas.common.latitude_NS; /* N/S */
assert(c == 'N' || c == 'S');
wpt->latitude = atof(line.bas.common.latitude_num);
if (c == 'S') {
/* handle date/time fields */
{
- int date, time;
- date = atoi(line.bas.common.date);
- time = atoi(line.bas.common.time);
+ int date = atoi(line.bas.common.date);
+ int time = atoi(line.bas.common.time);
wpt->SetCreationTime(bintime2utc(date, time));
}
track_add_wpt(track, wpt);
if (line.bas.common.tag != 'T') {
- Waypoint* wpt2;
// A 'G' tag appears to be a 'T' tag, but generated on the trailing
// edge of a DGPS fix as it decays to an SPS fix. See 1/13/13 email
// thread on gpsbabel-misc with Jamie Robertson.
assert(line.bas.common.tag == 'C' || line.bas.common.tag == 'G' ||
line.bas.common.tag == 'V');
- wpt2 = new Waypoint(*wpt);
+ Waypoint* wpt2 = new Waypoint(*wpt);
if (line.bas.common.tag == 'V') { // waypoint with voice recording?
char vox_file_name[sizeof(line.adv.vox)+5];
const char* vox = is_advanced_mode ? line.adv.vox : line.bas.vox;
static void
vcf_print_utf(const utf_string* s)
{
- char* p, *p2, *p3;
- char* stripped_html;
-
if (!s) {
return;
}
- stripped_html = strip_html(s);
- p = gstrsub(stripped_html, "\n", "\\n");
- p2 = gstrsub(p, "<p>", "\\n");
- p3 = gstrsub(p2, ";", "\\;");
+ char* stripped_html = strip_html(s);
+ char* p = gstrsub(stripped_html, "\n", "\\n");
+ char* p2 = gstrsub(p, "<p>", "\\n");
+ char* p3 = gstrsub(p2, ";", "\\;");
gbfputs(p3, file_out);
xfree(p);
xfree(p2);
static void
vcf_print(const char* s)
{
- char* p;
-
if (!s) {
return;
}
- p = gstrsub(s, "\n", "\\n");
+ char* p = gstrsub(s, "\n", "\\n");
gbfputs(p, file_out);
xfree(p);
}
static void
vcf_disp(const Waypoint* wpt)
{
- int latint, lonint;
-
- lonint = abs((int) wpt->longitude);
- latint = abs((int) wpt->latitude);
+ int lonint = abs((int) wpt->longitude);
+ int latint = abs((int) wpt->latitude);
gbfprintf(file_out, "BEGIN:VCARD\nVERSION:3.0\n");
gbfprintf(file_out, "N:%s;%s;;;\n", CSTRc(wpt->description),CSTRc(wpt->shortname));
#endif
{
const size_t arglen = strlen(argname);
- char* arglist;
char* rval = nullptr;
char* argp;
return nullptr;
}
- arglist = xstrdup(iarglist);
+ char* arglist = xstrdup(iarglist);
for (char* arg = arglist; argp = strtok(arg, ","), nullptr != argp; arg = nullptr) {
if (0 == case_ignore_strncmp(argp, argname, arglen)) {
void
disp_vecs()
{
- vecs_t** svp;
int vc;
- svp = sort_and_unify_vecs(&vc);
+ vecs_t** svp = sort_and_unify_vecs(&vc);
for (int i = 0; i<vc; i++) {
if (svp[i]->vec->type == ff_type_internal) {
continue;
void
disp_vec(const char* vecname)
{
- vecs_t** svp;
int vc;
- svp = sort_and_unify_vecs(&vc);
+ vecs_t** svp = sort_and_unify_vecs(&vc);
for (int i = 0; i<vc; i++) {
if (case_ignore_strcmp(svp[i]->name, vecname)) {
continue;
int16_t alt, speed_raw;
uint16_t hdg_raw;
uint8_t sats, hdop_raw, vdop_raw;
- Waypoint* waypt;
struct tm tm;
// The files have DOS line endings (CR/LF) but we don't care, because we
ymd /= 100;
tm.tm_year = ymd % 100 + 100;
- waypt = new Waypoint;
+ Waypoint* waypt = new Waypoint;
// Lat/Lon are both stored *0xE1000 which we have to divide out
// for decimal degrees
foreach(Waypoint* waypointp, waypt_list) {
#else
queue* elem, *tmp;
- Waypoint* waypointp;
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
- waypointp = (Waypoint*) elem;
+ Waypoint* waypointp = (Waypoint*) elem;
#endif
waypt_add_to_bounds(bounds, waypointp);
}
foreach(Waypoint* waypointp, waypt_list) {
#else
queue* elem, *tmp;
- Waypoint* waypointp;
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
- waypointp = (Waypoint*) elem;
+ Waypoint* waypointp = (Waypoint*) elem;
#endif
if (waypointp->shortname == name) {
return waypointp;
void
waypt_backup(signed int* count, queue** head_bak)
{
- queue* elem, *tmp, *qbackup;
+ queue* elem, *tmp;
Waypoint* wpt;
int no = 0;
- qbackup = (queue*) xcalloc(1, sizeof(*qbackup));
+ queue* qbackup = (queue*) xcalloc(1, sizeof(*qbackup));
QUEUE_INIT(qbackup);
#if NEWQ
// Why does this code exist?
gcgeodist(const double lat1, const double lon1,
const double lat2, const double lon2)
{
- double res;
-
- res = radtometers(gcdist(RAD(lat1), RAD(lon1), RAD(lat2), RAD(lon2)));
+ double res = radtometers(gcdist(RAD(lat1), RAD(lon1), RAD(lat2), RAD(lon2)));
if (res < 0.1) {
res = 0; /* calc. diffs on 32- and 64-bit hosts */
}
double
waypt_speed_ex(const Waypoint* A, const Waypoint* B)
{
- double dist, time;
-
- dist = waypt_distance_ex(A, B);
+ double dist = waypt_distance_ex(A, B);
if (dist == 0) {
return 0;
}
- time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0;
+ double time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0;
if (time > 0) {
return (dist / time);
} else {
double
waypt_speed(const Waypoint* A, const Waypoint* B)
{
- double dist, time;
-
- dist = waypt_distance(A, B);
+ double dist = waypt_distance(A, B);
if (dist == 0) {
return 0;
}
- time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0;
+ double time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0;
if (time > 0) {
return (dist / time);
} else {
double
waypt_vertical_speed(const Waypoint* A, const Waypoint* B)
{
- double altitude, time;
-
- altitude = A->altitude - B->altitude;
+ double altitude = A->altitude - B->altitude;
if (altitude == 0) {
return 0;
}
- time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0;
+ double time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0;
if (time > 0) {
return (altitude / time);
} else {
double
waypt_gradient(const Waypoint* A, const Waypoint* B)
{
- double dist, altitude, gradient;
- dist = waypt_distance(A, B);
+ double dist = waypt_distance(A, B);
if (dist == 0) {
return 0;
}
- altitude = A->altitude - B->altitude;
+ double altitude = A->altitude - B->altitude;
if (altitude == 0 ||
A->altitude == unknown_alt || B->altitude == unknown_alt) {
return 0;
}
- gradient = (altitude / dist) * 100;
+ double gradient = (altitude / dist) * 100;
return (gradient);
}
static void buf_extend(struct buf_head* h, size_t amt)
{
- struct buf_chunk* c;
size_t sz = amt + sizeof(struct buf_chunk);
- c = (struct buf_chunk*) xmalloc(sz);
+ struct buf_chunk* c = (struct buf_chunk*) xmalloc(sz);
c->next = nullptr;
c->size = amt;
c->used = 0;
static int wbt200_data_chunk(struct read_state* st, const void* buf, int fmt)
{
- uint32_t tim;
- double lat, lon, alt;
- time_t rtim;
+ double alt;
const char* bp = (const char*) buf;
size_t buf_used = fmt_version[fmt].reclen;
- tim = le_read32(bp + 0);
+ uint32_t tim = le_read32(bp + 0);
- lat = (double)((int32_t) le_read32(bp + 4)) / 10000000;
- lon = (double)((int32_t) le_read32(bp + 8)) / 10000000;
+ double lat = (double)((int32_t) le_read32(bp + 4)) / 10000000;
+ double lon = (double)((int32_t) le_read32(bp + 8)) / 10000000;
/* Handle extra fields in longer records here. */
if (buf_used >= 16) {
alt = unknown_alt;
}
- rtim = decode_date(tim);
+ time_t rtim = decode_date(tim);
if (lat >= 100) {
/* Start new track in the northern hemisphere */
for (;;) {
size_t got = buf_read(h, buf, reclen);
- uint32_t tim;
/* Don't mind odd bytes at the end - we may
* be examining an incomplete dataset.
*/
break;
}
- tim = le_read32(buf + 0);
+ uint32_t tim = le_read32(buf + 0);
if (!check_date(tim)) {
return 0;
}
*/
char line_buf[100];
int fmt;
- unsigned long count;
struct read_state st;
state_init(&st);
/* Now we're into binary mode */
rd_buf(line_buf, 6); /* six byte header */
- count = le_read16(line_buf + 2) + 1;
+ unsigned long count = le_read16(line_buf + 2) + 1;
if (count == 0x10000) {
count = 0;
}
static int wbt201_data_chunk(struct read_state* st, const void* buf)
{
- uint32_t tim;
- uint16_t flags;
- double lat, lon, alt;
- time_t rtim;
const char* bp = (const char*) buf;
/* Zero records are skipped */
return 1;
}
- flags = le_read16(bp + 0);
- tim = le_read32(bp + 2);
+ uint16_t flags = le_read16(bp + 0);
+ uint32_t tim = le_read32(bp + 2);
if (TK1_END_FLAG == tim) {
/* EOF? (TK1 files only as far as I know) */
return 0;
}
- lat = (double)((int32_t) le_read32(bp + 6)) / 10000000;
- lon = (double)((int32_t) le_read32(bp + 10)) / 10000000;
- alt = (double)((int16_t) le_read16(bp + 14));
+ double lat = (double)((int32_t) le_read32(bp + 6)) / 10000000;
+ double lon = (double)((int32_t) le_read32(bp + 10)) / 10000000;
+ double alt = (double)((int16_t) le_read16(bp + 14));
- rtim = decode_date(tim);
+ time_t rtim = decode_date(tim);
if ((flags & WBT201_WAYPOINT) && (global_opts.masked_objective & WPTDATAMASK)) {
Waypoint* wpt = make_waypoint(st, lat, lon, alt, rtim);
{
char cmd_buf[30];
char line_buf[100];
- unsigned long cs;
- char* lp, *op;
+ char* op;
static const char* cs_prefix = "@AL,CS,";
unsigned want = limit - pos;
return 0;
}
- lp = line_buf + strlen(cs_prefix);
- cs = strtoul(lp, &op, 16);
+ char* lp = line_buf + strlen(cs_prefix);
+ unsigned long cs = strtoul(lp, &op, 16);
if (*lp == ',' || *op != ',') {
db(2, "Badly formed checksum\n");
return 0;
{
char line_buf[100];
struct read_state st;
- unsigned tries;
-
- const char* tmp;
-
- double ver_hw;
- double ver_sw;
- double ver_fmt;
-
- unsigned log_addr_start;
- unsigned log_addr_end;
- unsigned log_area_start;
- unsigned log_area_end;
-
- unsigned wantbytes;
- unsigned read_pointer;
- unsigned read_limit;
/* Read various device information. We don't use much of this yet -
* just log_addr_start and log_addr_end - but it's useful to have it
* here for debug and documentation purposes.
*/
- tmp = get_param("@AL,7,1", BUFSPEC(line_buf));
+ const char* tmp = get_param("@AL,7,1", BUFSPEC(line_buf));
db(1, "Reading device \"%s\"\n", tmp);
- ver_hw = get_param_float("@AL,8,1");
- ver_sw = get_param_float("@AL,8,2");
- ver_fmt = get_param_float("@AL,8,3");
+ double ver_hw = get_param_float("@AL,8,1");
+ double ver_sw = get_param_float("@AL,8,2");
+ double ver_fmt = get_param_float("@AL,8,3");
db(2, "versions: hw=%f, sw=%f, fmt=%f\n",
ver_hw, ver_sw, ver_fmt);
- log_addr_start = get_param_int("@AL,5,1"); /* we read from here... */
- log_addr_end = get_param_int("@AL,5,2"); /* ...to here, but ... */
- log_area_start = get_param_int("@AL,5,9"); /* ...we need these when ... */
- log_area_end = get_param_int("@AL,5,10"); /* ...the gps wrote more then it fits in memory */
+ unsigned log_addr_start = get_param_int("@AL,5,1"); /* we read from here... */
+ unsigned log_addr_end = get_param_int("@AL,5,2"); /* ...to here, but ... */
+ unsigned log_area_start = get_param_int("@AL,5,9"); /* ...we need these when ... */
+ unsigned log_area_end = get_param_int("@AL,5,10"); /* ...the gps wrote more then it fits in memory */
db(2, "Log addr=(%d..%d), area=(%d..%d)\n",
log_addr_start, log_addr_end,
state_init(&st);
- tries = 10;
+ unsigned tries = 10;
/* If the WBT-201 device logs more then the memory can handle it continues to write at the beginning of the memory,
* thus overwriting the oldest tracks. In this case log_addr_end is smaller then log_addr_start and we need to read
* from log_addr_start to log_area_end and then from log_area_start to log_addr_end.
*/
- wantbytes = (log_addr_start < log_addr_end) ? log_addr_end - log_addr_start : log_area_end - (log_addr_start - log_addr_end);
- read_pointer = log_addr_start;
- read_limit = (log_addr_start < log_addr_end) ? log_addr_end : log_area_end;
+ unsigned wantbytes = (log_addr_start < log_addr_end) ? log_addr_end - log_addr_start : log_area_end - (log_addr_start - log_addr_end);
+ unsigned read_pointer = log_addr_start;
+ unsigned read_limit = (log_addr_start < log_addr_end) ? log_addr_end : log_area_end;
db(2, "Want %d bytes from device\n", wantbytes);
while (wantbytes > 0) {
static void file_read()
{
char buf[512];
- size_t rc;
struct read_state st;
int fmt;
state_init(&st);
/* Read the whole file into the buffer */
- rc = fread(buf, 1, sizeof(buf), fl);
+ size_t rc = fread(buf, 1, sizeof(buf), fl);
while (rc != 0) {
buf_write(&st.data, buf, rc);
rc = fread(buf, 1, sizeof(buf), fl);
track_add_head(trk);
while (!gbfeof(fin)) {
- Waypoint* wpt;
uint16_t flags = gbfgetuint16(fin);
uint32_t date = gbfgetuint32(fin);
int32_t latitude = gbfgetint32(fin);
int16_t alt = gbfgetint16(fin); // Signed. Meters.
(void) flags; // Silence 'unused' warning until we use flags.
- wpt = new Waypoint;
+ Waypoint* wpt = new Waypoint;
wpt->latitude = latitude / 1.0e7;
wpt->longitude = longitude / 1.0e7;
wpt->SetCreationTime(wintec_date_to_time(date));
// FIXME: should not be a static buf. Should not be a raw character
// buffer at all!
char ibuf[4096];
- size_t i;
while (*sbuff) {
ibuf[0] = 0;
- i = 0;
+ size_t i = 0;
char* ibufp;
for (ibufp = ibuf; *sbuff != '\n' && i++ < sizeof(ibuf);) {
*ibufp++ = *sbuff++;
xcsv_read_style(const char* fname)
{
char* sbuff;
- gbfile* fp;
xcsv_file_init();
- fp = gbfopen(fname, "rb", MYNAME);
+ gbfile* fp = gbfopen(fname, "rb", MYNAME);
while ((sbuff = gbfgetstr(fp))) {
sbuff = lrtrim(sbuff);
xcsv_parse_style_line(sbuff);
xg_callback*
xml_tbl_lookup(const QString& tag, xg_cb_type cb_type)
{
- xg_tag_mapping* tm;
- for (tm = xg_tag_tbl; tm->tag_cb != nullptr; tm++) {
+ for (xg_tag_mapping* tm = xg_tag_tbl; tm->tag_cb != nullptr; tm++) {
if (str_match(CSTR(tag), tm->tag_name) && (cb_type == tm->cb_type)) {
return tm->tag_cb;
}
static void
free_xml_tag(xml_tag* tag)
{
- char** ap;
-
while (tag) {
if (tag->child) {
free_gpx_extras(tag->child);
}
if (tag->attributes) {
- ap = tag->attributes;
+ char** ap = tag->attributes;
while (*ap) {
xfree(*ap++);